is_same 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +56 -0
  2. data/lib/is_same/core_ext.rb +5 -5
  3. metadata +3 -2
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ Installation
2
+ ============
3
+
4
+ ```bash
5
+ gem install is_same
6
+ ```
7
+
8
+ Why?
9
+ ====
10
+
11
+ To evaluate if different kind of objects have the same value or meaning, comparing objects without the need to worry about their type.
12
+
13
+ Supports Regexp.
14
+
15
+
16
+ Usage
17
+ =====
18
+
19
+ ```ruby
20
+ require 'is_same'
21
+ ```
22
+
23
+ ### These evaluate to False:
24
+
25
+ ```ruby
26
+ "String".matching?("tring") # Same as: "String" == "tring"
27
+ Object.new.matching?(Object.new) # Same as: Object.new == Object.new
28
+ ```
29
+
30
+ ### These evaluate to True:
31
+
32
+ ```ruby
33
+ :String.matching?("String") # Same as: :String.to_s == "String"
34
+ String.matching?(/tring/) # Same as: /tring/.match(String.name)
35
+ "String".matching?(String) # Same as: "String" == String.name
36
+
37
+ "1".matching?(1) # Same as: "1" == 1.to_s
38
+ 0.001.matching?("0.001") # Same as: 0.001.to_s == "0.001"
39
+ 123456.matching?(/234/) # Same as: /234/.match(123456.to_s)
40
+
41
+ [11, 22, 33].elements_matching?(/2/) # @see Array#elements_matching?
42
+ [44, 55, 66].elements_matching?() {|element| element == 66 }
43
+ [44, 55, 66].elements_matching?(lambda{|element| element == 66 })
44
+
45
+ ```
46
+
47
+ ### This returns matching elements in the Array:
48
+
49
+ ```ruby
50
+ {key1: :value1, key2: :value2}.keys.elements_matching(/ke/) # Returns [:key1, :key2]
51
+ {key1: 2, key2: 4}.values.elements_matching() {|element| element > 1 } # Returns [2, 4]
52
+ {key1: 2, key2: 4}.values.elements_matching(lambda{|element| element > 1 }) # Returns [2, 4]
53
+ ```
54
+
55
+
56
+ More examples can be seen in Rspec tests: https://github.com/tione/is_same/tree/master/spec
@@ -1,10 +1,10 @@
1
1
  class Object
2
2
  def matching? object=nil, &block
3
- case
4
- when object
5
- return self == object
6
- when block
7
- return block.call(self)
3
+ if object.is_a?(Proc) or block
4
+ object ||= block
5
+ object.call(self)
6
+ else
7
+ self == object
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_same
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000 Z
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -82,6 +82,7 @@ executables: []
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
+ - README.md
85
86
  - Gemfile
86
87
  - lib/is_same/core_ext.rb
87
88
  - lib/is_same.rb