Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Last active January 4, 2017 02:26
Show Gist options
  • Save amatsuda/4bc554e41398bd44f5d95eaee797924d to your computer and use it in GitHub Desktop.
Save amatsuda/4bc554e41398bd44f5d95eaee797924d to your computer and use it in GitHub Desktop.
`using` in Refinements should be physically placed before the refined method call
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)
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