Installation

gem install is_same

Why?

To evaluate if different kind of objects have the same value or meaning, comparing objects without the need to worry about their type.

Supports Regexp.

Usage

require 'is_same'

These evaluate to False:

"String".matching?("tring")      # Same as: "String" == "tring"
Object.new.matching?(Object.new) # Same as: Object.new == Object.new

These evaluate to True:

:String.matching?("String")      # Same as: :String.to_s == "String"
String.matching?(/tring/)        # Same as: /tring/.match(String.name)
"String".matching?(String)       # Same as: "String" == String.name

"1".matching?(1)                 # Same as: "1" == 1.to_s
0.001.matching?("0.001")         # Same as: 0.001.to_s == "0.001"
123456.matching?(/234/)          # Same as: /234/.match(123456.to_s)

[11, 22, 33].elements_matching?(/2/) # @see Array#elements_matching?
[44, 55, 66].elements_matching?() {|element| element == 66 } 
[44, 55, 66].elements_matching?(lambda{|element| element == 66 }) 

This returns matching elements in the Array:

{key1: :value1, key2: :value2}.keys.elements_matching(/ke/) # Returns [:key1, :key2]
{key1: 2, key2: 4}.values.elements_matching() {|element| element > 1 } # Returns [2, 4]
{key1: 2, key2: 4}.values.elements_matching(lambda{|element| element > 1 }) # Returns [2, 4]

More examples can be seen in Rspec tests: https://github.com/tione/is_same/tree/master/spec