Bug #9452

Refining methods that should be private

Added by Jan Lelis 3 months ago. Updated 2 months ago.

[ruby-core:60111]
Status:Closed
Priority:Normal
Assignee:Shugo Maeda
Category:-
Target version:-
ruby -v:ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux] Backport:1.9.3: DONTNEED, 2.0.0: DONE, 2.1: DONE

Description

Are refinements also meant to add private methods? This is what I tried:

module R
  refine Object do
    def m
      puts "Success!"
    end

    private(:m)
  end
end

using R

m # success
42.m # success (= not private)

However, I can get near the desired functionality by defining a private method first:

class Object
  private
  def m
  end
end

module R
  refine Object do
    def m
      puts "Success!"
    end
  end
end

using R
m # success
42.m # no success (= it is private)

It calls the right code. But requires global core ext.

Associated revisions

Revision 44931
Added by Shugo Maeda 2 months ago

  • vminsnhelper.c (vmcall_method): should check ci->me->flag of
    a refining method in case the method is private.
    [Bug #9452]

  • vmmethod.c (makemethodentryrefined): set me->flag of a refined
    method entry to NOEXPUBLIC in case the original method is private
    and it is refined as a public method. The original flag is stored
    in me->def->body.orig
    me, so it's OK to make a refined method
    entry public. [Bug #9452]

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

History

#1 Updated by Shugo Maeda 2 months ago

  • Assignee set to Shugo Maeda

#2 Updated by Shugo Maeda 2 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r44931.


  • vminsnhelper.c (vmcall_method): should check ci->me->flag of
    a refining method in case the method is private.
    [Bug #9452]

  • vmmethod.c (makemethodentryrefined): set me->flag of a refined
    method entry to NOEXPUBLIC in case the original method is private
    and it is refined as a public method. The original flag is stored
    in me->def->body.orig
    me, so it's OK to make a refined method
    entry public. [Bug #9452]

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

#3 Updated by Tomoyuki Chikanaga 2 months ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED

#4 Updated by Tomoyuki Chikanaga 2 months ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: REQUIRED

r44931 was backported to ruby20_0 at r44967.

#5 Updated by Yui NARUSE 2 months ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONE, 2.1: DONE

r45107.

Also available in: Atom PDF