ruby-changes:26303
From: nobu <ko1@a...>
Date: Thu, 13 Dec 2012 13:09:47 +0900 (JST)
Subject: [ruby-changes:26303] nobu:r38354 (trunk): method transplanting
nobu 2012-12-13 13:06:40 +0900 (Thu, 13 Dec 2012) New Revision: 38354 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38354 Log: method transplanting * proc.c (umethod_bind): allow another form of method transplanting from a module via UnboundMethod. [ruby-core:34267][Feature #4254] Modified files: trunk/ChangeLog trunk/proc.c trunk/test/ruby/test_method.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38353) +++ ChangeLog (revision 38354) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 13 13:06:27 2012 Nobuyoshi Nakada <nobu@r...> + + * proc.c (umethod_bind): allow another form of method transplanting + from a module via UnboundMethod. [ruby-core:34267][Feature #4254] + Thu Dec 13 12:07:25 2012 Shugo Maeda <shugo@r...> * include/ruby/ruby.h (RB_UNUSED_VAR): new macro to suppress Index: proc.c =================================================================== --- proc.c (revision 38353) +++ proc.c (revision 38354) @@ -1620,7 +1620,8 @@ umethod_bind(VALUE method, VALUE recv) https://github.com/ruby/ruby/blob/trunk/proc.c#L1620 TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); - if (data->rclass != CLASS_OF(recv) && !rb_obj_is_kind_of(recv, data->rclass)) { + if (!RB_TYPE_P(data->rclass, T_MODULE) && + data->rclass != CLASS_OF(recv) && !rb_obj_is_kind_of(recv, data->rclass)) { if (FL_TEST(data->rclass, FL_SINGLETON)) { rb_raise(rb_eTypeError, "singleton method called for a different object"); Index: test/ruby/test_method.rb =================================================================== --- test/ruby/test_method.rb (revision 38353) +++ test/ruby/test_method.rb (revision 38354) @@ -206,6 +206,10 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L206 def o.bar; end m = o.method(:bar).unbind assert_raise(TypeError) { m.bind(Object.new) } + + feature4254 = '[ruby-core:34267]' + m = M.instance_method(:meth) + assert_equal(:meth, m.bind(Object.new).call, feature4254) end def test_define_method -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/