c - how to analysis this excerpt of Ruby source code about === method -
i found example , metaphor of object#===
operatorare confusing, i'm begin read source code, i'm new c, tell me how analysis code:
value rb_equal(value obj1, value obj2) { value result; if (obj1 == obj2) return qtrue; result = rb_funcall(obj1, id_eq, 1, obj2); if (rtest(result)) return qtrue; return qfalse; }
value
generic type of ruby objects in c (as opposed c types int
). can deduce rb_equal
function comparing 2 ruby objects (obj1
, obj2
). if 2 objects equal qtrue
(the represantion of ruby's true in c) returned. if not rb_funcall
call equality method (id_eq
) on obj1
. if result truthy (checked rtest(result)
) qtrue
returned. if hit end of function 2 objects not same, we'll return false (qfalse
).
Comments
Post a Comment