Map with class' method
class Human
def initialize
[1, 2, 3].map(&method(:random))
end
def random(seed)
42
end
end
Written by Adam Stankiewicz
Related protips
4 Responses

Pretty sure the & is superfluous, #method should return a callable :)
over 1 year ago
·

@richoh Nope. method
returns Method class, and we need to pass block. afaik ampersand operator is the only way to convert proc / lambda / method to block.
over 1 year ago
·

Ah, my bad. Thanks for clearing that up.
over 1 year ago
·

For the unenlightened...like me :-. What is the underlying intent in the above example?
Any hints appreciated.
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#