views:

41

answers:

0

Those stupid 'string'.method! returning nil instead of self in ruby - can be easily overriden:

class String
    ['strip!', 'upcase!', 'downcase!', 'capitalize!', 'chop!', 'chomp!', 'delete!', 'gsub!'].each do |meth|
        orig_meth = "orig_#{meth}"
        alias_method orig_meth, meth
        define_method(meth) do |*args|
            self.send(orig_meth, *args)
            self
        end
    end
end

old "nil"-methods are also available via "orig_methodname" or whatever prefix you specify Hope, this helps somebody. Sorry for no question ))