Created
November 25, 2013 06:02
-
-
Save anshul/7636988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
puts "hello" << "meow" << "rofl" | |
class String | |
def <<(arg) | |
puts "#{self.to_s} called with #{arg.inspect}" | |
"#{self}#{arg}" | |
end | |
end | |
puts "hello" << "meow" << "rofl" | |
# Result with ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] => | |
# | |
# hellomeowrofl | |
# test_associativity.rb:5: warning: method redefined; discarding old << | |
# hello called with "meow" | |
# hellomeow called with "rofl" | |
# hellomeowrofl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment