Created
April 6, 2015 17:23
-
-
Save paul/404bb1ad3d5d18bf3ec8 to your computer and use it in GitHub Desktop.
Ruby Refinement Inheritance
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
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