Skip to content

Commit

Permalink
Fix Module#define_method
Browse files Browse the repository at this point in the history
When defining a method through a proc which gets created out of a method
which is defined in a C-ext, `meth.ruby_method.executable` is a instance of
Rubinius::NativeCode and not Rubinius::CompiledCode which does not
respond to #scope.

This is used for example in pg gem:
https://github.com/ged/ruby-pg/blob/bb4693e811f9348f202835e701e6509d15685b0a/lib/pg/connection.rb#L187
  • Loading branch information
tak1n committed Feb 5, 2016
1 parent 40f04c1 commit d436251
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/module.rb
Expand Up @@ -446,7 +446,11 @@ def define_method(name, meth = undefined, &prc)
when Proc
if meth.ruby_method
code = Rubinius::DelegatedMethod.new(name, :call, meth, false)
scope = meth.ruby_method.executable.scope
if meth.ruby_method.executable.kind_of? Rubinius::CompiledCode
scope = meth.ruby_method.executable.scope
else
scope = nil
end
else
be = meth.block.dup
be.change_name name
Expand Down

0 comments on commit d436251

Please sign in to comment.