Symbol#to_proc to retrieve a method from current refinement
Currently Symbol#to_proc retrieves the global definition of the method, since refinement is a lexical scope.
But if possible, it is better that Symbol#to_proc can retrieve a method from current refinement.
refine Integer do
def bar; p :bar; end
1.bar # => :bar
[1,2].each(&:bar) # => undefined method `bar'
What do you think?
It should be done before 2.0.0 if we merge, to avoid future compatibility issues.
Updated by shugo (Shugo Maeda) over 7 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r37418.
Yukihiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
string.c (sym_to_proc, sym_call): A Proc created by Symbol#to_proc
should close over the current refinements.
[ruby-dev:46345] [Bug #7261]
vm_eval.c (rb_call0, rb_search_method_entry,
rb_funcall_passing_block_with_refinements): add a new argument
`refinements' for the above changes.
test/ruby/test_refinement.rb: related test.