Skip to content

Commit

Permalink
implement Proc#for_define_method
Browse files Browse the repository at this point in the history
  • Loading branch information
tak1n committed Feb 5, 2016
1 parent d436251 commit 040c726
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 1 addition & 15 deletions core/module.rb
Expand Up @@ -444,21 +444,7 @@ def define_method(name, meth = undefined, &prc)

case meth
when Proc
if meth.ruby_method
code = Rubinius::DelegatedMethod.new(name, :call, meth, false)
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
code = Rubinius::BlockEnvironment::AsMethod.new(be)
meth = meth.dup
meth.lambda_style!
scope = meth.block.scope
end
code, scope = meth.for_define_method(name)
when Method
Rubinius::Type.bindable_method? meth.defined_in, self.class

Expand Down
20 changes: 20 additions & 0 deletions core/proc.rb
Expand Up @@ -244,6 +244,26 @@ def dup
copy
end

def for_define_method(name)
if @ruby_method
code = Rubinius::DelegatedMethod.new(name, :call, self, false)
if @ruby_method.executable.kind_of? Rubinius::CompiledCode
scope = @ruby_method.executable.scope
else
scope = nil
end
else
be = @block.dup
be.change_name name
code = Rubinius::BlockEnvironment::AsMethod.new(be)
meth = self.dup
meth.lambda_style!
scope = meth.block.scope
end

[code, scope]
end

def self.from_method(meth)
if meth.kind_of? Method
return __from_method__(meth)
Expand Down

0 comments on commit 040c726

Please sign in to comment.