Project

General

Profile

Actions

Bug #15274

closed

Reflection does not report methods defined only in refinements

Added by pitr.ch (Petr Chalupa) about 6 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:89663]

Description

class C
end

module M
  refine C do
    def foo
      puts "C#foo in M"
    end
  end
end

using M

c = C.new
c.foo # prints "C#foo in M"
c.send :foo
p c.respond_to? :foo
p c.methods.include?(:foo)
p C.instance_methods.include?(:foo)
p((c.method(:foo) rescue false))

__END__
Prints:

C#foo in M
C#foo in M
false
false
false
false

When the refinement M is used I think it would be less surprising if reflection methods (respond_to?, methods, method, instance_methods) report available methods including the ones coming from refinement.

Updated by matz (Yukihiro Matsumoto) about 6 years ago

  • Status changed from Open to Closed

It's intentional. Refinements are only seen from the lexical scope. That means reflection methods does not see any methods defined only in refinements.

Matz.

Actions

Also available in: Atom PDF

Like0
Like0