From: Robert Klemme Date: 2013-01-29T22:08:29+09:00 Subject: Re: Please explain in English On Tue, Jan 29, 2013 at 1:19 PM, Joel Pearson wrote: > Ryan Davis wrote in post #1094171: >> This modifies the argument coming in. Don't ever call downcase! or other >> mutating methods on an argument or you'll wind up in debugging hell. >> Make a copy instead: >> >> string = string.downcase > > Ah, I didn't know that a bang method would also change the argument > outside of the current scope as well! Dangerous. That's why there is the exclamation mark in the first place. It means "potentially dangerous method" (defined by Matz). Btw, this does not have that much to do with scope but it's rather which object gets changed. All places in code which reference that particular instance will notice the change once they use the object. > irb(main):001:0> a = 'a' > => "a" > irb(main):002:0> def t1(b) > irb(main):003:1> b.upcase > irb(main):004:1> end > => nil > irb(main):005:0> def t2(b) > irb(main):006:1> b.upcase! > irb(main):007:1> end > => nil > irb(main):008:0> t1 a > => "A" > irb(main):009:0> a > => "a" > irb(main):010:0> t2 a > => "A" > irb(main):011:0> a > => "A" Yeah, String methods with exclamation mark typically change the instance itself whereas the "less dangerous" brothers typically return a modified instance. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/