看 ruby programming。irb 里面尝试。发现了一个小问题。求解。
2.3.0 :001 > puts { name: 'yzhao',email: '[email protected]' }.class
SyntaxError: (irb):1: syntax error, unexpected ':', expecting '}'
puts {name: 'yzhao',email: '[email protected]' }.class
^
(irb):1: syntax error, unexpected ',', expecting '}'
puts {name: 'yzhao',email: '[email protected]' }.class
^
from /Users/zhaoyongping/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
2.3.0 :002 > a = {name: 'yzhao',email: '[email protected]' }.class
=> Hash
2.3.0 :003 > puts a
Hash
=> nil
2.3.0 :004 >
我仔细想了下,难道是优先级的问题,先 puts {}.然后再取 class?貌似不合常理啊。