File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,14 @@ def cool_method
350
350
object2 . other_cool_method . should == "data is foo"
351
351
end
352
352
353
+ it "accepts a proc from a Symbol" do
354
+ symbol_proc = :+ . to_proc
355
+ klass = Class . new do
356
+ define_method :foo , &symbol_proc
357
+ end
358
+ klass . new . foo ( 1 , 2 ) . should == 3
359
+ end
360
+
353
361
it "maintains the Proc's scope" do
354
362
class DefineMethodByProcClass
355
363
in_scope = true
@@ -715,3 +723,46 @@ def nested_method_in_proc_for_define_method
715
723
end
716
724
end
717
725
end
726
+
727
+ describe "Method#define_method when passed a block" do
728
+ describe "behaves exactly like a lambda" do
729
+ it "for return" do
730
+ Class . new do
731
+ define_method ( :foo ) do
732
+ return 42
733
+ end
734
+ end . new . foo . should == 42
735
+ end
736
+
737
+ it "for break" do
738
+ Class . new do
739
+ define_method ( :foo ) do
740
+ break 42
741
+ end
742
+ end . new . foo . should == 42
743
+ end
744
+
745
+ it "for next" do
746
+ Class . new do
747
+ define_method ( :foo ) do
748
+ next 42
749
+ end
750
+ end . new . foo . should == 42
751
+ end
752
+
753
+ it "for redo" do
754
+ Class . new do
755
+ result = [ ]
756
+ define_method ( :foo ) do
757
+ if result . empty?
758
+ result << :first
759
+ redo
760
+ else
761
+ result << :second
762
+ result
763
+ end
764
+ end
765
+ end . new . foo . should == [ :first , :second ]
766
+ end
767
+ end
768
+ end
You can’t perform that action at this time.
0 commit comments