o:$YARD::CodeObjects::MethodObject:
@name: bind:@docstringIC:YARD::Docstring"FBind umeth to obj. If Klass
was the class
from which umeth was obtained,
obj.kind_of?(Klass)
must be true.
class A
def test
puts "In test, class = #{self.class}"
end
end
class B < A
end
class C < B
end
um = B.instance_method(:test)
bm = um.bind(C.new)
bm.call
bm = um.bind(B.new)
bm.call
bm = um.bind(A.new)
bm.call
produces:
In test, class = C
In test, class = B
prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
from prog.rb:16
:@objectu:YARD::StubProxyUnboundMethod#bind:
@summary0: @all"\Bind umeth to obj. If Klass
was the class
from which umeth was obtained,
obj.kind_of?(Klass)
must be true.
class A
def test
puts "In test, class = #{self.class}"
end
end
class B < A
end
class C < B
end
um = B.instance_method(:test)
bm = um.bind(C.new)
bm.call
bm = um.bind(B.new)
bm.call
bm = um.bind(A.new)
bm.call
produces:
In test, class = C
In test, class = B
prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
from prog.rb:16
@overload bind(obj):@ref_tags[ :
@tags[o:YARD::Tags::OverloadTag
;
u;UnboundMethod#bind;;;IC; "
;
u;UnboundMethod#bind;0;
" ;[ ;[ :@types0:@parameters[[:obj0:
@text0:@signature"bind(obj):@tag_name"
overload:@current_file_has_commentsF:@scope:
instance;[ :@docstring_extra0:@files[["eval.c0:@namespaceu;UnboundMethod:
@path"UnboundMethod#bind;[ :@visibility:public:@source"Ï/*
* call-seq:
* umeth.bind(obj) -> method
*
* Bind umeth to obj. If Klass
was the class
* from which umeth was obtained,
* obj.kind_of?(Klass)
must be true.
*
* class A
* def test
* puts "In test, class = #{self.class}"
* end
* end
* class B < A
* end
* class C < B
* end
*
*
* um = B.instance_method(:test)
* bm = um.bind(C.new)
* bm.call
* bm = um.bind(B.new)
* bm.call
* bm = um.bind(A.new)
* bm.call
*
* produces:
*
* In test, class = C
* In test, class = B
* prog.rb:16:in `bind': bind argument must be an instance of B (TypeError)
* from prog.rb:16
*/
static VALUE
umethod_bind(method, recv)
VALUE method, recv;
{
struct METHOD *data, *bound;
VALUE rklass = CLASS_OF(recv);
Data_Get_Struct(method, struct METHOD, data);
if (data->rklass != rklass) {
if (FL_TEST(data->rklass, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "singleton method bound for a different object");
}
if (TYPE(data->rklass) == T_MODULE) {
st_table *m_tbl = RCLASS(data->rklass)->m_tbl;
while (RCLASS(rklass)->m_tbl != m_tbl) {
rklass = RCLASS(rklass)->super;
if (!rklass) goto not_instace;
}
}
else if (!rb_obj_is_kind_of(recv, data->rklass)) {
not_instace:
rb_raise(rb_eTypeError, "bind argument must be an instance of %s",
rb_class2name(data->rklass));
}
}
method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound);
*bound = *data;
bound->recv = recv;
bound->rklass = rklass;
return method;
}:@source_type:c