Skip to content

Instantly share code, notes, and snippets.

@anithri
Last active August 29, 2015 14:15
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 anithri/29a75f68669a130e3e26 to your computer and use it in GitHub Desktop.
Save anithri/29a75f68669a130e3e26 to your computer and use it in GitHub Desktop.
are there any gotcha's for this refinement scheme?
# Small module intended for enhancing a string object.
module Joy
def joy
self + ' Joy!'
end
end
# setup the Refinement using include
require_relative 'joy'
module RefinedJoy
refine String do
include Joy
end
end
require_relative 'refined_joy'
module TestPositive
using RefinedJoy
puts "refined? ".joy #> refined? Joy!
end
module TestNegative
puts "refined? ".joy #> NoMethodError "undefined method `joy' for "Refined?":String"
end
require_relative 'joy'
String.include(Joy)
puts "monkey patched?".joy #> monkey patched? Joy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment