Skip to content

Instantly share code, notes, and snippets.

@mariozig
Last active October 21, 2017 20:06
Show Gist options
  • Save mariozig/627007536f9e3b93c4ac55fb9368cad8 to your computer and use it in GitHub Desktop.
Save mariozig/627007536f9e3b93c4ac55fb9368cad8 to your computer and use it in GitHub Desktop.
The result of using a refinement -- from post http://ruby.zigzo.com/2017/10/21/refinements-fancy-monkey/
# Our code calling `to_s` on an Integer has been refined
puts CrazyInteger.crazy_string(2)
# => "TWO, ALWAYS TWO!!!!"
puts CrazyInteger.crazy_string(3)
# => "TWO, ALWAYS TWO!!!!"
# Regular calls to Integer.to_s are still safe!
puts 1.to_s
# => "1"
puts 2.to_s
# => "2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment