Skip to content
Permalink
Browse files
implement Method#for_define_method, add second argument klass to for_…
…define_method which is needed by Method and UnboundMethod
  • Loading branch information
tak1n committed Feb 5, 2016
1 parent 040c726 commit 2e501b5888c8ae73ee1199d8a190b99482b4718b
Showing with 25 additions and 20 deletions.
  1. +22 −0 core/method.rb
  2. +2 −19 core/module.rb
  3. +1 −1 core/proc.rb
@@ -172,6 +172,28 @@ def super_method
return nil
end

def for_define_method(name, klass)
Rubinius::Type.bindable_method? self.defined_in, klass

# We see through delegated methods because code creates these crazy calls
# to define_method over and over again and if we don't check, we create
# a huge delegated method chain. So instead, just see through them at one
# level always.
if @executable.kind_of? Rubinius::DelegatedMethod
code = @executable
scope = nil
else
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, self.unbind, true)
if @executable.kind_of? Rubinius::CompiledCode
scope = @executable.scope
else
scope = nil
end
end

[code, scope]
end

end

##
@@ -444,26 +444,9 @@ def define_method(name, meth = undefined, &prc)

case meth
when Proc
code, scope = meth.for_define_method(name)
code, scope = meth.for_define_method(name, nil)
when Method
Rubinius::Type.bindable_method? meth.defined_in, self.class

exec = meth.executable
# We see through delegated methods because code creates these crazy calls
# to define_method over and over again and if we don't check, we create
# a huge delegated method chain. So instead, just see through them at one
# level always.
if exec.kind_of? Rubinius::DelegatedMethod
code = exec
scope = nil
else
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, meth.unbind, true)
if exec.kind_of? Rubinius::CompiledCode
scope = exec.scope
else
scope = nil
end
end
code, scope = meth.for_define_method(name, self.class)
when UnboundMethod
Rubinius::Type.bindable_method? meth.defined_in, self.class

@@ -244,7 +244,7 @@ def dup
copy
end

def for_define_method(name)
def for_define_method(name, klass)
if @ruby_method
code = Rubinius::DelegatedMethod.new(name, :call, self, false)
if @ruby_method.executable.kind_of? Rubinius::CompiledCode

0 comments on commit 2e501b5

Please sign in to comment.