Skip to content

Commit

Permalink
cleanup Method#for_define_method and UnboundMethod#for_define_method,…
Browse files Browse the repository at this point in the history
… delegate responsibility further to executables
  • Loading branch information
tak1n committed Feb 5, 2016
1 parent 510919d commit 7cd4315
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
6 changes: 6 additions & 0 deletions core/block_environment.rb
Expand Up @@ -102,6 +102,12 @@ def file
def defined_line
@block_env.line
end

def for_define_method(name, meth)
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, meth, true)

[code, nil]
end
end

def from_proc?
Expand Down
6 changes: 6 additions & 0 deletions core/compiled_code.rb
Expand Up @@ -212,6 +212,12 @@ def breakpoint?(ip)
raise ArgumentError, "Unable to retrieve breakpoint status on #{inspect} at bytecode address #{ip}"
end

def for_define_method(name, meth)
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, meth, true)

[code, @scope]
end

class Script
attr_accessor :compiled_code
attr_accessor :file_path
Expand Down
4 changes: 4 additions & 0 deletions core/delegated_method.rb
Expand Up @@ -31,5 +31,9 @@ def parameters
def source_location
@receiver.source_location
end

def for_define_method(name, meth)
[self, nil]
end
end
end
33 changes: 2 additions & 31 deletions core/method.rb
Expand Up @@ -175,25 +175,8 @@ def super_method
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]
@executable.for_define_method(name, self.unbind)
end

end

##
Expand Down Expand Up @@ -342,18 +325,6 @@ def super_method
def for_define_method(name, klass)
Rubinius::Type.bindable_method? self.defined_in, klass

if @executable.kind_of? Rubinius::DelegatedMethod
code = @executable
scope = nil
else
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, self, true)
if @executable.kind_of? Rubinius::CompiledCode
scope = @executable.scope
else
scope = nil
end
end

[code, scope]
@executable.for_define_method(name, self)
end
end
6 changes: 6 additions & 0 deletions core/native_method.rb
Expand Up @@ -78,5 +78,11 @@ def defined_line
def active_path
@file
end

def for_define_method(name, meth)
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, meth, true)

[code, nil]
end
end
end

0 comments on commit 7cd4315

Please sign in to comment.