зеркало из https://github.com/github/ruby.git
method transplanting
* proc.c (umethod_bind): allow another form of method transplanting from a module via UnboundMethod. [ruby-core:34267][Feature #4254] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
cd9d004e7f
Коммит
0667541894
|
@ -1,3 +1,8 @@
|
|||
Thu Dec 13 13:06:27 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* include/ruby/ruby.h (RB_UNUSED_VAR): new macro to suppress
|
||||
|
|
3
proc.c
3
proc.c
|
@ -1620,7 +1620,8 @@ umethod_bind(VALUE method, VALUE recv)
|
|||
|
||||
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");
|
||||
|
|
|
@ -206,6 +206,10 @@ class TestMethod < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче