H
Henrik
I haven't been able to figure out how to write a destructive string
method of my own. How do I change the value of "self"? This is what I
tried first:
class String
alias_methodorig_upcase, :upcase)
def upcase
orig_upcase.tr("åäö", "ÅÄÖ")
end
def upcase!
self = self.upcase
end
end
"upcase" works fine but "upcase!" doesn't - "can't change the value of
self". Nor can I do (assuming another alias_method):
def upcase!
self.old_upcase!
self.tr!("åäö", "ÅÄÖ")
end
or the same thing chained (self.old_upcase!.tr!(...)), because that only
returns nil. I've even grasped for straws like
def upcase!
=(self.upcase)
end
with no luck. Very grateful for any help.
method of my own. How do I change the value of "self"? This is what I
tried first:
class String
alias_methodorig_upcase, :upcase)
def upcase
orig_upcase.tr("åäö", "ÅÄÖ")
end
def upcase!
self = self.upcase
end
end
"upcase" works fine but "upcase!" doesn't - "can't change the value of
self". Nor can I do (assuming another alias_method):
def upcase!
self.old_upcase!
self.tr!("åäö", "ÅÄÖ")
end
or the same thing chained (self.old_upcase!.tr!(...)), because that only
returns nil. I've even grasped for straws like
def upcase!
=(self.upcase)
end
with no luck. Very grateful for any help.