Last active
January 4, 2017 02:26
-
-
Save amatsuda/4bc554e41398bd44f5d95eaee797924d to your computer and use it in GitHub Desktop.
`using` in Refinements should be physically placed before the refined method call
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
class String | |
def bar() foo; end | |
end | |
using Module.new { | |
refine String do | |
def foo() p self; end | |
end | |
} | |
'hello'.bar | |
#=> doesnot_work.rb:2:in `bar': undefined local variable or method `foo' for "hello":String (NameError) |
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
using Module.new { | |
refine String do | |
def foo() p self; end | |
end | |
} | |
class String | |
def bar() foo; end | |
end | |
'hello'.bar | |
#=> "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment