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
Post a Comment