Ruby 有 lambda 语法,所以我可以使用这个->
符号:
a = 0
new -> { a < 5 } do
puts a
a += 1
end
这很好用,但是当我尝试这样做时:
match "/", to: -> { |e| [404, {}, ["Hello! I am micro rack app"]] }, via: [:get]
match( "/", to: -> { |e| [404, {}, ["Hello! I am micro rack app"]] }, via: [:get] )
match( "/", { to: -> { |e| [404, {}, ["Hello! I am micro rack app"]] }, via: [:get] })
所有返回相同的语法错误:
$ ruby -c -e 'match( "/", to: -> { |e| [404, {}, ["Hello! I am micro rack app"]] }, via: [:get] )'
-e:1: syntax error, unexpected '|'
match( "/", to: -> { |e| [404, {}, ["Hello! I am mi...
我错过了什么吗?