summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-12-26 17:42:41 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2013-12-26 17:42:41 +0900
commit2ec67c651ee29ab7c9a9c8fdce91a81377e52bd2 (patch)
tree21f8a265f57ca1619daafd35f56a84318dd72e0a
parentb72f3f92f7282d7c68a09004ed3824316948dd8d (diff)
parenta89cba9fa486b852ec99598d73ddc6f35ee4bbc8 (diff)
downloadmruby-2ec67c651ee29ab7c9a9c8fdce91a81377e52bd2.tar.gz
mruby-2ec67c651ee29ab7c9a9c8fdce91a81377e52bd2.zip
Merge branch 'singletonfix' of https://github.com/carsonmcdonald/mruby into carsonmcdonald-singletonfix
-rw-r--r--src/codegen.c1
-rw-r--r--test/t/class.rb34
2 files changed, 35 insertions, 0 deletions
diff --git a/src/codegen.c b/src/codegen.c
index fc83244f2..731d94319 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -2331,6 +2331,7 @@ codegen(codegen_scope *s, node *tree, int val)
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
if (val) {
push();
+ push();
}
}
break;
diff --git a/test/t/class.rb b/test/t/class.rb
index d6c0f1c9a..680cd253c 100644
--- a/test/t/class.rb
+++ b/test/t/class.rb
@@ -258,3 +258,37 @@ assert('Class#inherited') do
assert_equal(Baz, Foo.subclass_name)
end
+
+assert('singleton tests') do
+ bar = String.new
+
+ baz = class << bar
+ def self.run_baz
+ 200
+ end
+ end
+
+ assert_false baz.singleton_methods.include? :run_baz
+
+ assert_raise(NoMethodError, 'should raise NoMethodError') do
+ baz.run_baz
+ end
+
+ assert_raise(NoMethodError, 'should raise NoMethodError') do
+ bar.run_baz
+ end
+
+ baz = class << bar
+ def self.run_baz
+ 300
+ end
+ self
+ end
+
+ assert_true baz.singleton_methods.include? :run_baz
+ assert_equal 300, baz.run_baz
+
+ assert_raise(NoMethodError, 'should raise NoMethodError') do
+ bar.run_baz
+ end
+end