Skip to content

Commit

Permalink
add example which specs behavior of Proc#for_define_method when procs…
Browse files Browse the repository at this point in the history
… @ruby_method is set
  • Loading branch information
tak1n committed Feb 6, 2016
1 parent 21bede5 commit 7a8f1dc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/ruby/core/module/define_method_spec.rb
Expand Up @@ -180,6 +180,26 @@ def inspect_data
lambda{o.other_inspect}.should raise_error(NoMethodError)
end

it "accepts a proc from a method" do
class ProcFromMethod
attr_accessor :data
def cool_method
"data is #{@data}"
end
end

o = ProcFromMethod.new
o.data = :foo

p = o.method(:cool_method).to_proc
klass = Class.new(ProcFromMethod)
klass.send(:define_method, :other_cool_method, p)

object = klass.new
object.data = :bar
object.other_cool_method.should == "data is foo"
end

it "maintains the Proc's scope" do
class DefineMethodByProcClass
in_scope = true
Expand Down

0 comments on commit 7a8f1dc

Please sign in to comment.