Proc#[] is an alias for Proc#call
lambda:
doubler = ->(i) { i + i }
'normal' way of calling a proc:
doubler.call(4)
=> 8
added in 1.9:
doubler.(4)
=> 8
using array element access style syntax:
doubler[4]
=> 8
this also works (but will confuse everyone that sees it!):
doubler === 4
=> 8
Written by Gino Lucero
Related protips
1 Response
Wow Ruby can make no sense sometimes. :P
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#