Skip to content

Instantly share code, notes, and snippets.

@nusco
Created March 4, 2014 16:51
Show Gist options
  • Save nusco/9350331 to your computer and use it in GitHub Desktop.
Save nusco/9350331 to your computer and use it in GitHub Desktop.
Spell: Refinement
# =================
# 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