What does -> mean in Ruby -


this question has answer here:

i've seen in spree commerce.

go_to_state :confirm, if: ->(order) { order.confirmation_required? } 

so what'll symbol?

it lambda literal. check example:

 > plus_one = ->(x){x+1}  => #<proc:0x9fbaa00@(irb):3 (lambda)>   > plus_one.call(3)  => 4  

a lambda literal constructor proc. proc way have block of code assigned variable. after this, can call block of code again, different arguments, many times wish.

this how can pass "function" parameter in ruby. in many languages, pass reference function. in ruby, can pass proc object.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -