Bug #7261

Symbol#to_proc to retrieve a method from current refinement

Added by Yukihiro Matsumoto over 1 year ago. Updated over 1 year ago.

[ruby-dev:46345]
Status:Closed
Priority:Normal
Assignee:Shugo Maeda
Category:core
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-11-01 trunk 37415) [i486-linux] Backport:

Description

Currently Symbol#toproc 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.

module Silly
refine Integer do
def bar; p :bar; end
end
end

module Stupid
using Silly
1.bar # => :bar
[1,2].each(&:bar) # => undefined method `bar'
end

What do you think?

It should be done before 2.0.0 if we merge, to avoid future compatibility issues.

Matz.

Associated revisions

Revision 37418
Added by Shugo Maeda over 1 year ago

  • string.c (symtoproc, symcall): A Proc created by Symbol#toproc
    should close over the current refinements.
    [Bug #7261]

  • vmeval.c (rbcall0, rbsearchmethodentry,
    rb
    funcallpassingblockwithrefinements): add a new argument
    `refinements' for the above changes.

  • test/ruby/test_refinement.rb: related test.

History

#1 Updated by Shugo Maeda over 1 year 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 (symtoproc, symcall): A Proc created by Symbol#toproc
    should close over the current refinements.
    [Bug #7261]

  • vmeval.c (rbcall0, rbsearchmethodentry,
    rb
    funcallpassingblockwithrefinements): add a new argument
    `refinements' for the above changes.

  • test/ruby/test_refinement.rb: related test.

Also available in: Atom PDF