Project

General

Profile

Feature #10426

A predicate to express congruence

Added by sawa (Tsuyoshi Sawada) over 4 years ago. Updated over 4 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:65900]

Description

I occasionally felt the necessity of a predicate that checks congruence with respect to some operations:

class Object
    def equal_by? other, &pr
        pr.call(self) == pr.call(other)
    end
    alias congruent? equal_by?
end

5.congruent?(2){|e| e % 3} #=> true
"HELLO".equal_by?("Hello", &:downcase) #=> true

History

Updated by gogotanaka (Kazuki Tanaka) over 4 years ago

@Tsuyoshi Sawada san
I like it.

One thing I'm a little worried about is congruent? might be too specified word.
I mean, I'm not sure congruent can be used in except modulo or geometry context.

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

How about similar? or analog? ?

Also available in: Atom PDF