On Mon, Feb 11, 2013 at 10:04 AM, Joel Pearson <[email protected]> wrote:
> Nice one Henry. As usual Ruby has more than one way to do everything :)
IMHO #tap is only called for in these situations
- The value to be tapped is the result of evaluating an expression
(and not already stored in a variable) AND
- It should be used as the result of the larger expression.
Typical example:
module Enumerable
def group_by
{}.tap do |groups|
each do |e|
(groups[yield(e)] ||= []) << e
end
end
end
end
In all other cases doing a simple assignment like
mo = my_object
mo = my.complicated.expression
is probably easier, cleaner and faster.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--
[email protected] |
https://groups.google.com/d/forum/ruby-talk-google?hl=en
---
You received this message because you are subscribed to the Google Groups
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.