Skip to content

Commit

Permalink
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/method.rb
Original file line number Diff line number Diff line change
@@ -337,16 +337,20 @@ def super_method
def for_define_method(name, klass, callable_proc = nil)
Rubinius::Type.bindable_method? self.defined_in, klass

scope = @executable.scope

if @executable.is_a? Rubinius::DelegatedMethod
case @executable
when Rubinius::AccessVariable
code = @executable
scope = nil
when Rubinius::DelegatedMethod
code = @executable
scope = code.scope
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
scope = @executable.scope
end

[code, scope]
17 changes: 17 additions & 0 deletions spec/ruby/core/module/define_method_spec.rb
Original file line number Diff line number Diff line change
@@ -180,6 +180,23 @@ def inspect_data
lambda{o.other_inspect}.should raise_error(NoMethodError)
end

it "accepts an UnboundMethod from an attr_accessor method" do
class DefineMethodSpecClass
attr_accessor :accessor_method
end

m = DefineMethodSpecClass.instance_method(:accessor_method)
o = DefineMethodSpecClass.new

DefineMethodSpecClass.send(:undef_method, :accessor_method)
lambda { o.accessor_method }.should raise_error(NoMethodError)

DefineMethodSpecClass.send(:define_method, :accessor_method, m)

o.accessor_method = :abc
o.accessor_method.should == :abc
end

it "accepts a proc from a method" do
class ProcFromMethod
attr_accessor :data

0 comments on commit 8a6c33a

Please sign in to comment.