G
Gabriel Saravia
The Ruby API specifies that objects of the Method class have an instance
method "==": "Two method objects are equal if that are bound to the
same object and contain the same body."
At this moment, I would very much like it if it also had a "=~" method:
"two method objects are similar if they contain the same body but are
NOT necessarily bound to the same object"
unfortunately I'm not currently skilled enough to really understand the
C code in which the "==" method for the Method class is written. could
someone help me out here? Below I've replicated the C code for the "=="
method with some changes to reflect what the =~ method would look like:
static VALUE
method_similar(method, other)
VALUE method, other;
{
struct METHOD *m1, *m2;
if (TYPE(other) != T_DATA || RDATA(other)->dmark !=
(RUBY_DATA_FUNC)bm_mark)
return Qfalse; //I Do Not understand what this if statement does
if (CLASS_OF(method) != CLASS_OF(other))
return Qfalse; //I assume this makes sure that the classes of
both methods is Method?
Data_Get_Struct(method, struct METHOD, m1);//No clue but looks
harmless enough
Data_Get_Struct(other, struct METHOD, m2); //No clue but looks
harmless enough
if (m1->klass != m2->klass ||
m1->rklass != m2->rklass || //this condition looks like it ALSO
checks that the classes of both methods is Method, so I must be missing
something somewhere...
m1->recv != m2->recv || // <-!! Would all that need to happen is
this line be eliminated??
m1->body != m2->body)
return Qfalse;
return Qtrue;
}
Also, how can you modify Ruby to include this function, so i can use it
in my Rails tests?
-Gabe
method "==": "Two method objects are equal if that are bound to the
same object and contain the same body."
At this moment, I would very much like it if it also had a "=~" method:
"two method objects are similar if they contain the same body but are
NOT necessarily bound to the same object"
unfortunately I'm not currently skilled enough to really understand the
C code in which the "==" method for the Method class is written. could
someone help me out here? Below I've replicated the C code for the "=="
method with some changes to reflect what the =~ method would look like:
static VALUE
method_similar(method, other)
VALUE method, other;
{
struct METHOD *m1, *m2;
if (TYPE(other) != T_DATA || RDATA(other)->dmark !=
(RUBY_DATA_FUNC)bm_mark)
return Qfalse; //I Do Not understand what this if statement does
if (CLASS_OF(method) != CLASS_OF(other))
return Qfalse; //I assume this makes sure that the classes of
both methods is Method?
Data_Get_Struct(method, struct METHOD, m1);//No clue but looks
harmless enough
Data_Get_Struct(other, struct METHOD, m2); //No clue but looks
harmless enough
if (m1->klass != m2->klass ||
m1->rklass != m2->rklass || //this condition looks like it ALSO
checks that the classes of both methods is Method, so I must be missing
something somewhere...
m1->recv != m2->recv || // <-!! Would all that need to happen is
this line be eliminated??
m1->body != m2->body)
return Qfalse;
return Qtrue;
}
Also, how can you modify Ruby to include this function, so i can use it
in my Rails tests?
-Gabe