3 ms·
Yes, the lambda was equivalent. However, the second example offers that it might be better to be more verbose and avoid the use of anonymous functions. In gener
by msellout 11y ago
Yes, the lambda was equivalent. However, the second example offers that it might be better to be more verbose and avoid the use of anonymous functions. In general, I prefer to define a block and name parameters.
As the slideshow illustrated, it's all about having good taste as an author. Knowing your audience and all that. In fact, that might have been a good point to add to his slides--that different coding styles are appropriate for different teams and projects.
- spoiler 11y agoI'm not sure if I am misunderstanding your argument, but it seems like you're complaining about the fact you can't pass "functions" to methods that accept a block? You can! :D times_two = -> (x) {x*2} # Proc (lambda) times_two = Proc.new {|x| x*2} # Proc [7, 13, 19, 23, 31].map(×_two) Also, if you want to call a method on the objects, you could do: [7, 13, 19, 23, 31].map(&:to_s) Which is a bizarre syntax, if you ask me (actually, not really if you know how I works in the background, but it still does look bizarre IHMO).