File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -499,6 +499,36 @@ def foo
499
499
Class . new { define_method :bar , m }
500
500
} . should raise_error ( TypeError , /can't bind singleton method to a different class/ )
501
501
end
502
+
503
+ it "defines the new method public when the definition frame self is different from the target" do
504
+ foo_class = Class . new do
505
+ private def bar
506
+ "public"
507
+ end
508
+ end
509
+
510
+ foo = foo_class . new
511
+ foo . singleton_class . define_method ( :bar , foo . method ( :bar ) )
512
+
513
+ foo . bar . should == "public"
514
+ end
515
+
516
+ it "defines the new method according to the scope when the definition context is the same" do
517
+ FooWithOneBar = Class . new do
518
+ def bar ; end
519
+ end
520
+
521
+ foo = FooWithOneBar . new
522
+
523
+ class << foo
524
+ private
525
+ define_method ( :bar , FooWithOneBar . new . method ( :bar ) )
526
+ end
527
+
528
+ -> { foo . bar } . should raise_error ( NoMethodError )
529
+
530
+ Object . class_eval { remove_const ( :FooWithOneBar ) }
531
+ end
502
532
end
503
533
504
534
describe "Module#define_method" do
You can’t perform that action at this time.
0 commit comments