In irb I have defined the lambda
f=lambda { |x| x+1 }
and then issued (because I have seen it in someone else code)
f.(10)
which computed 11. But what does the f.(10) syntax mean? It computes the
same as f(10), but why?
In irb I have defined the lambda
f=lambda { |x| x+1 }
and then issued (because I have seen it in someone else code)
f.(10)
which computed 11. But what does the f.(10) syntax mean? It computes the
same as f(10), but why?
f.(10) is an alias for f.call(10) - see documentation for Proc#call
f(10) won’t work, you’ve probably meant f[10] as an equivalent method
call.
Thank you!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs