1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

method transplanting

* proc.c (rb_mod_define_method): allow method transplanting from a
  module to either class or module.  [ruby-core:34267][Feature #4254]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-06-25 07:57:42 +00:00
parent 0f0f0f4441
commit e6f1e3f49d
3 changed files with 13 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Mon Jun 25 16:57:38 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (rb_mod_define_method): allow method transplanting from a
module to either class or module. [ruby-core:34267][Feature #4254]
Mon Jun 25 15:42:00 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (is_popen_fork): check if fork and raise NotImplementedError if

3
proc.c
View file

@ -1360,7 +1360,8 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
if (rb_obj_is_method(body)) {
struct METHOD *method = (struct METHOD *)DATA_PTR(body);
VALUE rclass = method->rclass;
if (rclass != mod && !RTEST(rb_class_inherited_p(mod, rclass))) {
if (rclass != mod && !RB_TYPE_P(rclass, T_MODULE) &&
!RTEST(rb_class_inherited_p(mod, rclass))) {
if (FL_TEST(rclass, FL_SINGLETON)) {
rb_raise(rb_eTypeError,
"can't bind singleton method to a different class");

View file

@ -36,7 +36,7 @@ class TestMethod < Test::Unit::TestCase
module M
def func; end
module_function :func
def meth; end
def meth; :meth end
end
def mv1() end
@ -230,9 +230,11 @@ class TestMethod < Test::Unit::TestCase
Module.new.module_eval {define_method(:foo, Base.instance_method(:foo))}
end
assert_raise(TypeError) do
Class.new.class_eval {define_method(:meth, M.instance_method(:meth))}
end
feature4254 = '[ruby-core:34267]'
m = Module.new {define_method(:meth, M.instance_method(:meth))}
assert_equal(:meth, Object.new.extend(m).meth, feature4254)
c = Class.new {define_method(:meth, M.instance_method(:meth))}
assert_equal(:meth, c.new.meth, feature4254)
end
def test_super_in_proc_from_define_method