Last active
October 21, 2017 20:06
-
-
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/
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
# 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