On Thu, Feb 14, 2013 at 1:43 PM, Edoardo Rossi <[email protected]> wrote:
> IMHO sometimes this is useful:
>
> def foo(something)
>   dup.foo!(something)
> end
>
> def foo!(something)
>   # do the work...
> end

There is one gotcha in this code: foo! will often return nil if
nothing is changed.  A better approach is

def foo(something)
  dup.tap {|copy| copy.foo!(something)}
end

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.


Reply via email to