From: her@... Date: 2014-11-13T08:34:47+00:00 Subject: [ruby-core:66254] [ruby-trunk - Feature #10505] [PATCH 2/n] 同相条件を扱いたい./Object#eql? with block. (ja/en) Issue #10505 has been updated by Shota Fukumori. `%w(RUBY Ruby).map(&:downcase).uniq.size == 1` covers multiple elements, but note that the original proposal doesn't cover such situation. ---------------------------------------- Feature #10505: [PATCH 2/n] ���������������������������./Object#eql? with block. (ja/en) https://bugs.ruby-lang.org/issues/10505#change-49933 * Author: gogo tanaka * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: ---------------------------------------- English follows japanese ## ������ ������������������������������������������������������������������������������������������������������������������������. ```ruby a % 2 == b % 2 a.abs == b.abs "RUBY".downcase == "Ruby".downcase ``` ������������������������������������������������������������������������������������������������������������������������������������������. ���������������������������������������������������������. ������������������������������������������������������������������������������������������������������������������������������������ ## ������ ���������������������������������������`#eql?`������������������������������������������������������������������. ```ruby # 2������������������������ a.eql?(b) { |n| n % 2 } # ���������������������������������������������������������������������������������������������������������������. "RUBY".eql?("Ruby", &:downcase) ``` ## ��������� * block������������`#===`������������������������������������������������. ```ruby 1.eql?(1.0, &:itself) # => true 1.eql?(1.0) # => false ``` * ���������������������`#eql?`������������������������������������������������������ ���������������������������������������������������������������������������������������������������������������������`Numeric#eql?`������������������������������ ������������������������������������������������������������������������������������������������������������������������������. ���������������������������������. ## Motivation We often encounter a situation where we need to compare both operands after certain function apply for these. ```ruby a % 2 == b % 2 a.abs == b.abs "RUBY".downcase == "Ruby".downcase ``` I am not willing to write same function both operands. This is main motivation. ## Proposal Now if the optional block is given, compare between results of running block for both operands. ```ruby # check wether `a` and `b` are congruent modulo 2 or not a.eql?(b) { |n| n % 2 } "RUBY".eql?("Ruby", &:downcase) ``` I've found similar issue [here](https://bugs.ruby-lang.org/issues/10426) For now, I've implemented for `Numeric#eql?` If it looks like good for you, I'm gonna implement for other Classes ## Concern * We'll compare by using `#===` after passed to block. so it may look like weird. ```ruby 1.eql?(1.0, &:itself) # => true 1.eql?(1.0) # => false ``` Thanks, gogo. ---Files-------------------------------- Update_Numeric#eql_.patch (1.23 KB) Add_tests_for_Numeric#eql_.patch (748 Bytes) -- https://bugs.ruby-lang.org/