From: Robert Klemme Date: 2013-07-06T06:21:25+09:00 Subject: Re: Implementing sort/sort! --001a11c2c150dd510804e0ca4639 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jul 5, 2013 at 8:22 PM, wrote: > Am 03.07.2013 09:30, schrieb Robert Klemme: > > Usually with pairs of bang and non bang methods one can do >> >> def meth! >> # logic >> self >> end >> >> def meth >> dup.tap {|copy| copy.meth!} >> end >> > > Hi Robert, > > I'm probably missing something obvious, but why not simply use > > def meth > dup.meth! > end > > ? > Duh. No, you're not missing anything here. The only defense I have for the other form I have is that it is independent of the return value of #meth! - if you think of String#gsub! for example then your short version will not work because sometimes that method will return nil. That's probably the reason I made my form a habit. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --001a11c2c150dd510804e0ca4639 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Fri, Jul 5, 2013 at 8:22 PM, <sto.mar@web.de> wrote= :
Am 03.07.2013 09:30, schrieb Robert Klemme:

Usually with pairs of bang and non bang methods one can do

def meth!
=A0 =A0# logic
=A0 =A0self
end

def meth
=A0 =A0dup.tap {|copy| copy.meth!}
end

Hi Robert,

I'm probably missing something obvious, but why not simply use

=A0 def meth
=A0 =A0 dup.meth!
=A0 end

?

Duh. =A0No, you're not m= issing anything here. =A0The only defense I have for the other form I have = is that it is independent of the return value of #meth! - if you think of S= tring#gsub! for example then your short version will not work because somet= imes that method will return nil. =A0That's probably the reason I made = my form a habit. :-)

Kind regard= s

robe= rt

--
remember.guy do |a= s, often| as.you_can - without end
http://blog.rubybestpractice= s.com/
--001a11c2c150dd510804e0ca4639--