summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-06-24 13:11:36 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-06-24 13:13:59 +0900
commit888be9611b60bc7739d797e6defaf903b260b62d (patch)
treee10e43fe7a071def02906780238c7bba2ae25614 /test
parentf314a5132edb5efbb7c81b7f9c97d0197e001c1e (diff)
downloadmruby-888be9611b60bc7739d797e6defaf903b260b62d.tar.gz
mruby-888be9611b60bc7739d797e6defaf903b260b62d.zip
class.c: call hook methods on method definitions; close #2339
- `Module#method_added` - `BasicObject#singleton_method_added`
Diffstat (limited to 'test')
-rw-r--r--test/t/methods.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/t/methods.rb b/test/t/methods.rb
index f9c25dc33..9005d7976 100644
--- a/test/t/methods.rb
+++ b/test/t/methods.rb
@@ -107,3 +107,32 @@ assert('The undef statement (method undefined)', '13.3.7 a) 5)') do
undef :non_existing_method
end
end
+
+assert('method_added hook') do
+ c = Class.new do
+ # method to retrieve @name
+ def self.name; @name; end
+ # hook method on method definition
+ def self.method_added(name) @name = name; end
+ # method definition
+ def foo; end
+ end
+ assert_equal(:foo, c.name)
+ c.define_method(:bar){}
+ assert_equal(:bar, c.name)
+end
+
+assert('singleton_method_added hook') do
+ a = Object.new
+ # method to retrieve @name
+ def a.name; @name; end
+ # hook method on singleton method definition
+ def a.singleton_method_added(name) @name = name; end
+ # singleton method definition
+ def a.foo; end
+ assert_equal(:foo, a.name)
+ class <<a
+ def bar; end
+ end
+ assert_equal(:bar, a.name)
+end