summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-class-ext/test/module.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-12-20 20:18:25 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-12-23 10:01:30 +0900
commit8d7e95282c64f482a28e7bc579857e781d03c74b (patch)
tree758f1ffe54df84f99aa21f2dd8ee47969b41822f /mrbgems/mruby-class-ext/test/module.rb
parent7fbbd7ab9fdeb9eafe6a37fa7f16b60e41e21ad4 (diff)
downloadmruby-8d7e95282c64f482a28e7bc579857e781d03c74b.tar.gz
mruby-8d7e95282c64f482a28e7bc579857e781d03c74b.zip
Add `#module_exec` and `#class_exec` in `mruby-class-ext` gem.
Diffstat (limited to 'mrbgems/mruby-class-ext/test/module.rb')
-rw-r--r--mrbgems/mruby-class-ext/test/module.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/mrbgems/mruby-class-ext/test/module.rb b/mrbgems/mruby-class-ext/test/module.rb
index 65abde108..ed6713aac 100644
--- a/mrbgems/mruby-class-ext/test/module.rb
+++ b/mrbgems/mruby-class-ext/test/module.rb
@@ -32,3 +32,24 @@ assert 'Module#singleton_class?' do
assert_false cls.singleton_class?
assert_true scl.singleton_class?
end
+
+assert 'Module#module_eval' do
+ mod = Module.new
+ mod.class_exec(1,2,3) do |a,b,c|
+ assert_equal([1,2,3], [a,b,c])
+ def hi
+ "hi"
+ end
+ end
+ cls = Class.new
+ cls.class_exec(42) do |x|
+ assert_equal(42, x)
+ include mod
+ def hello
+ "hello"
+ end
+ end
+ obj = cls.new
+ assert_equal("hi", obj.hi)
+ assert_equal("hello", obj.hello)
+end