Am Dienstag, 05. Jun 2007, 22:16:33 +0900 schrieb [email protected]:
I think even the original idea probably wasn’t a good !-candidate
(since bang methods generally have non-bang equivalents, whereas
methods with names that imply change or other “danger” [like replace]
don’t),
As far as I see banged methods are mostly implemented as
class String
def modify_it!
…
end
def modify_it
str = dup
str.modify_it!
str
end
end
(Of course some C equivalent.)
So, if Mike means what he does he can easily add the
counterpart.
val="0" if self.downcase=="myvalue1"
val="1" if self.downcase=="myvalue2"
val
end
end
test=“myvalue1”
p test.change!
p test
I think even the original idea probably wasn’t a good !-candidate
(since bang methods generally have non-bang equivalents, whereas
methods with names that imply change or other “danger” [like replace]
don’t), and definitely if you’re not modifying the string or doing
anything else dangerous, the ! is not a good idea, since it’s out of
keeping with the convention.
David
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.