Project

General

Profile

Actions

Feature #10426

open

A predicate to express congruence

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

Status:
Open
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
Actions

Also available in: Atom PDF

Like0
Like0Like0