Skip to content

Commit

Permalink
Fix BasicObject.instance_eval on RBX
Browse files Browse the repository at this point in the history
Closes #61
  • Loading branch information
psyho committed Nov 28, 2014
1 parent 8839e99 commit 13751a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bogus/core_ext.rb
@@ -1,5 +1,5 @@
# This monkey patch should not break Ruby compatibility
# but is necessary because MRI, insead of calling object.kind_of?(module),
# but is necessary because MRI, instead of calling object.kind_of?(module),
# calls the C function, which implements kind_of. This makes
# using fake objects in switch cases produce unexpected results:
#
Expand All @@ -15,7 +15,11 @@
class Module
# don't warn about redefining === method
Bogus::Support.supress_warnings do
alias :__trequals__ :===

def ===(object)
# BasicObjects do not have kind_of? method
return __trequals__(object) unless Object.__trequals__(object)
object.kind_of?(self)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/bogus/bugs/rbx_instance_eval_bug_spec.rb
Expand Up @@ -11,4 +11,10 @@ def x
result = SampleForRbxInstanceEval.new.instance_eval{x}
expect(result).to eq(3)
end

it "does not break === with the monkey patch" do
expect(SampleForRbxInstanceEval === SampleForRbxInstanceEval.new).to be(true)
expect(BasicObject === SampleForRbxInstanceEval.new).to be(true)
expect(Bogus === SampleForRbxInstanceEval.new).to be(false)
end
end

0 comments on commit 13751a7

Please sign in to comment.