Calling/applying lambda vs. function call - the syntax in Ruby is different. Why?

前端 未结 3 615
囚心锁ツ
囚心锁ツ 2021-02-01 03:15

I am kinda new to Ruby and still trying to understand some of the language design principles. IF I\'ve got it right, the lambda expression call in Ruby must be with square brace

3条回答
  •  情歌与酒
    2021-02-01 03:27

    If you want brackets, you can do

    by_two = lambda { |x| x * 2 }
    by_two.(5) # => 10
    

    Note the . between by_two and (5).

提交回复
热议问题