Skip to content

Commit 7a8f1dc

Browse files
committedFeb 6, 2016
add example which specs behavior of Proc#for_define_method when procs @ruby_method is set
1 parent 21bede5 commit 7a8f1dc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎spec/ruby/core/module/define_method_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ def inspect_data
180180
lambda{o.other_inspect}.should raise_error(NoMethodError)
181181
end
182182

183+
it "accepts a proc from a method" do
184+
class ProcFromMethod
185+
attr_accessor :data
186+
def cool_method
187+
"data is #{@data}"
188+
end
189+
end
190+
191+
o = ProcFromMethod.new
192+
o.data = :foo
193+
194+
p = o.method(:cool_method).to_proc
195+
klass = Class.new(ProcFromMethod)
196+
klass.send(:define_method, :other_cool_method, p)
197+
198+
object = klass.new
199+
object.data = :bar
200+
object.other_cool_method.should == "data is foo"
201+
end
202+
183203
it "maintains the Proc's scope" do
184204
class DefineMethodByProcClass
185205
in_scope = true

0 commit comments

Comments
 (0)
Please sign in to comment.