This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.
Python has this by default, a function that receives a method and arguments and return a function that when called with an object call the method with the provided args. Perfect for usign with map and reduce family of fuctions. Here is how to achieve the same with ruby def methodcaller ( method , * args ) -> ( object ) { object . send ( method , * args ) } end [ 'foo' , 'boo' , 'zoo' ]. map ( &…
Python has this by default, a function that receives a method and arguments
and return a function that when called with an object call the method
with the provided args. Perfect for usign with map and reduce family of fuctions.
Here is how to achieve the same with ruby
def methodcaller(method, *args)
->(object) { object.send(method, *args) }
end
['foo', 'boo', 'zoo'].map(&methodcaller(:gsub, 'oo', 'aa'))
Cheers
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.