Skip to content

Instantly share code, notes, and snippets.

@paul
Created April 6, 2015 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul/404bb1ad3d5d18bf3ec8 to your computer and use it in GitHub Desktop.
Save paul/404bb1ad3d5d18bf3ec8 to your computer and use it in GitHub Desktop.
Ruby Refinement Inheritance
module MyExt
refine String do
def foo
"foo"
end
end
end
class Parent
using MyExt
def parent_foo
"xyz".foo
end
end
class Child < Parent
def child_foo
"xyz".foo
end
end
puts Parent.new.parent_foo # => "foo"
puts Child.new.child_foo # => undefined method `foo' for "xyz":String (NoMethodError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment