Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from Shopify/object-methods-included
Browse files Browse the repository at this point in the history
Don't try to intern MethodMirrors that are defined on Objects
  • Loading branch information
airhorns committed Feb 8, 2017
2 parents ca04492 + 9efea5d commit c9f8038
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/mirrors.rb
Expand Up @@ -193,7 +193,10 @@ def reflect_file(obj)

def reflect_method(obj)
mirror = MethodMirror.new(obj)
mirror.defining_class.intern_method_mirror(mirror)
if mirror.defining_class.respond_to?(:intern_method_mirror)
mirror = mirror.defining_class.intern_method_mirror(mirror)
end
mirror
end

def reflect_class(obj)
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/method.rb
Expand Up @@ -50,3 +50,24 @@ def shadow_without_super
def not_inherited
end
end

class HelperModule < Module
def initialize(something)
@something = something
end

def to_s
"Helper for #{@something}"
end
end

DYNAMIC_INCLUDE = HelperModule.new("fixture")

class ObjectIncludeFixture
include DYNAMIC_INCLUDE
end

DYNAMIC_INCLUDE.class_eval do
def method_from_dynamic_include
end
end
6 changes: 6 additions & 0 deletions test/mirrors/method_mirror_test.rb
Expand Up @@ -114,6 +114,12 @@ def test_private_method
assert_equal(:private, m.visibility)
end

def test_method_included_from_instance
method_mirror = Mirrors.reflect(ObjectIncludeFixture.new.method(:method_from_dynamic_include))
assert(method_mirror.public?)
assert_equal(method_mirror.defining_class.reflectee, DYNAMIC_INCLUDE)
end

private

def method_b(a, b = 1, bb = 2, *args, &block)
Expand Down

0 comments on commit c9f8038

Please sign in to comment.