def [](index)
case index
when 0, -2: @x
when 1, -1: @y
when :x, "x": @x
when :y, "y": @y
else nil
end
end
array.rb:3: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
when 0, -2: @x
^
array.rb:5: syntax error, unexpected ':', expecting keyword_end
when :x, "x": @x
^
array.rb:6: syntax error, unexpected ':', expecting keyword_end
when :y, "y": @y
^
array.rb:8: warning: else without rescue is useless
array.rb:9: syntax error, unexpected keyword_end, expecting $end
我是按照《Ruby 编程语言》这本书的原样写的。
我的 ruby 版本是 ruby 1.9.3p0
有没有人见过这个?