From 219ad6258a80d0083ddb2f64a01eaa63e542c620 Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Wed, 12 Nov 2014 16:16:43 -0800 Subject: [PATCH 1/2] *numeric.c: block can be passed to #eql? --- numeric.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/numeric.c b/numeric.c index 6819e4a..a002454 100644 --- a/numeric.c +++ b/numeric.c @@ -1049,15 +1049,22 @@ flo_pow(VALUE x, VALUE y) * * Returns +true+ if +num+ and +numeric+ are the same type and have equal * values. - * - * 1 == 1.0 #=> true - * 1.eql?(1.0) #=> false - * (1.0).eql?(1.0) #=> true + * If the optional +block+ is given, compare between results of running +block+ for +num+ and +numeric+. + * + * 1 == 1.0 #=> true + * 1.eql?(1.0) #=> false + * (1.0).eql?(1.0) #=> true + * 4.eql?(6) { |n| n % 2 } #=> true + * 3.eql?(-3, &:abs) #=> true + * 1.eql?(1.0, &:itself) #=> true */ static VALUE num_eql(VALUE x, VALUE y) { + if (rb_block_given_p()) { + return rb_equal(rb_yield(x), rb_yield(y)); + } if (TYPE(x) != TYPE(y)) return Qfalse; return rb_equal(x, y); -- 1.9.3 (Apple Git-50)