Skip to content

Instantly share code, notes, and snippets.

@nuna
Created November 8, 2011 10:45
Show Gist options
  • Save nuna/1347475 to your computer and use it in GitHub Desktop.
Save nuna/1347475 to your computer and use it in GitHub Desktop.
redefine String#+
$ irb
ruby-1.8.7-p352 :001 > str = 'a'
=> "a"
ruby-1.8.7-p352 :002 > str + 'b'
=> "ab"
ruby-1.8.7-p352 :003 > p str
"a"
=> nil
ruby-1.8.7-p352 :004 > class String
ruby-1.8.7-p352 :005?> def +(other)
ruby-1.8.7-p352 :006?> self.concat(other)
ruby-1.8.7-p352 :007?> end
ruby-1.8.7-p352 :008?> end
=> nil
ruby-1.8.7-p352 :009 > str2 = 'a'
=> "a"
ruby-1.8.7-p352 :010 > str2 + 'b'
=> "ab"
ruby-1.8.7-p352 :011 > p str2
"ab"
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment