Project

General

Profile

Actions

Bug #9452

closed

Refining methods that should be private

Added by rbjl (Jan Lelis) about 10 years ago. Updated about 10 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-01-25 trunk 44707) [x86_64-linux]
[ruby-core:60111]

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0