Created
March 4, 2014 16:51
-
-
Save nusco/9350331 to your computer and use it in GitHub Desktop.
Spell: Refinement
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
# ================= | |
# Spell: Refinement | |
# ================= | |
# Patch a class until the end of the file, or (from Ruby 2.1) until the end of the including module. | |
module MyRefinement | |
refine String do | |
def reverse | |
"my reverse" | |
end | |
end | |
end | |
"abc".reverse # => "cba" | |
using MyRefinement | |
"abc".reverse # => "my reverse" | |
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment