Skip to content
Permalink
Browse files
add example which specs behavior of Proc#for_define_method when procs…
… @ruby_method is set
  • Loading branch information
tak1n committed Feb 6, 2016
1 parent 21bede5 commit 7a8f1dc7885d0737c7102ad54679ec1ae06c9c36
Showing 1 changed file with 20 additions and 0 deletions.
@@ -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

0 comments on commit 7a8f1dc

Please sign in to comment.