Skip to content

Instantly share code, notes, and snippets.

@mariozig
Last active October 21, 2017 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariozig/33bf4dc780fa75cccf377fe440bd248b to your computer and use it in GitHub Desktop.
Save mariozig/33bf4dc780fa75cccf377fe440bd248b to your computer and use it in GitHub Desktop.
Bad idea to monkeypatch `.to_s` -- code for post: http://ruby.zigzo.com/2017/10/21/refinements-fancy-monkey/
irb(main):001:0> 1.class
=> Integer
irb(main):002:0> 1.to_s
=> "1"
irb(main):003:0> class Integer
irb(main):004:1> def to_s
irb(main):005:2> "two"
irb(main):006:2> end
irb(main):007:1> end
=> :to_s
irb(main):008:two> 1.to_s
=> "two"
irb(main):009:two> 3.to_s
=> "two"
# WHAT HAVE I DONE TO MY LIFE?!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment