好像题主发现了一个不怎么常见的错误
我试了下,正常情况下当 hash 的 key 是 object.method+1 这种形式,分词的时候可以正常解析
pry(main)> Ripper.lex("{ foo: bar.length+1 }")
=> [[[1, 0], :on_lbrace, "{"],
[[1, 1], :on_sp, " "],
[[1, 2], :on_label, "foo:"],
[[1, 6], :on_sp, " "],
[[1, 7], :on_ident, "bar"],
[[1, 10], :on_period, "."],
[[1, 11], :on_ident, "length"],
[[1, 17], :on_op, "+"],
[[1, 18], :on_int, "1"],
[[1, 19], :on_sp, " "],
[[1, 20], :on_rbrace, "}"]]
前面有一个空格时,并不能正常解析,+这个方法并没有被抓到
pry(main)> Ripper.lex("{ foo: bar.length +1 }")
=> [[[1, 0], :on_lbrace, "{"],
[[1, 1], :on_sp, " "],
[[1, 2], :on_label, "foo:"],
[[1, 6], :on_sp, " "],
[[1, 7], :on_ident, "bar"],
[[1, 10], :on_period, "."],
[[1, 11], :on_ident, "length"],
[[1, 17], :on_sp, " "],
[[1, 18], :on_int, "+1"],
[[1, 20], :on_sp, " "],
[[1, 21], :on_rbrace, "}"]]
这算是个 issue 吗?估计只是我们的使用姿势不对吧,把 + 两边都加上空格或者都不加就可以正常解析