Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 2e501b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
22 changes: 22 additions & 0 deletions core/method.rb
Expand Up @@ -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

##
Expand Down
21 changes: 2 additions & 19 deletions core/module.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/proc.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2e501b5

Please sign in to comment.