Skip to content

Commit

Permalink
implement Executable#scope, retrieving proper code part is responsibi…
Browse files Browse the repository at this point in the history
…lity of Method,UnboundMethod #for_define_method, add 3rd arg callabale_proc to Method,UnboundMethod #for_define_method
  • Loading branch information
tak1n committed Feb 5, 2016
1 parent 7cd4315 commit 5d2f054
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
6 changes: 2 additions & 4 deletions core/block_environment.rb
Expand Up @@ -103,10 +103,8 @@ 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]
def scope
nil
end
end

Expand Down
6 changes: 0 additions & 6 deletions core/compiled_code.rb
Expand Up @@ -212,12 +212,6 @@ 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: 2 additions & 2 deletions core/delegated_method.rb
Expand Up @@ -32,8 +32,8 @@ def source_location
@receiver.source_location
end

def for_define_method(name, meth)
[self, nil]
def scope
nil
end
end
end
32 changes: 28 additions & 4 deletions core/method.rb
Expand Up @@ -172,10 +172,22 @@ def super_method
return nil
end

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

@executable.for_define_method(name, self.unbind)
scope = @executable.scope

if @executable.is_a? Rubinius::DelegatedMethod
code = @executable
else
if callable_proc
code = Rubinius::DelegatedMethod.new(name, :call, callable_proc, false)
else
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, self.unbind, true)
end
end

[code, scope]
end
end

Expand Down Expand Up @@ -322,9 +334,21 @@ def super_method
return nil
end

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

@executable.for_define_method(name, self)
scope = @executable.scope

if @executable.is_a? Rubinius::DelegatedMethod
code = @executable
else
if callable_proc
code = Rubinius::DelegatedMethod.new(name, :call, callable_proc, false)
else
code = Rubinius::DelegatedMethod.new(name, :call_on_instance, self, true)
end
end

[code, scope]
end
end
6 changes: 2 additions & 4 deletions core/native_method.rb
Expand Up @@ -79,10 +79,8 @@ def active_path
@file
end

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

[code, nil]
def scope
nil
end
end
end

0 comments on commit 5d2f054

Please sign in to comment.