is_same 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/is_same/core_ext.rb +38 -32
  2. metadata +2 -2
@@ -1,18 +1,23 @@
1
- class BasicObject
2
- def is_same? object
3
- self == object
1
+ class Object
2
+ def matching? object=nil, &block
3
+ case
4
+ when object
5
+ return self == object
6
+ when block
7
+ return block.call(self)
8
+ end
4
9
  end
5
10
  end
6
11
 
7
12
  class Class
8
- def is_same? object
13
+ def matching? object=nil, &block
9
14
  case object
10
15
  when String
11
16
  object == self.name
12
17
  when Symbol
13
18
  object == self.name.to_sym
14
19
  when Regexp
15
- !!object.match( self.name )
20
+ !!object.match(self.name)
16
21
  else
17
22
  super
18
23
  end
@@ -20,14 +25,14 @@ class Class
20
25
  end
21
26
 
22
27
  class Numeric
23
- def is_same? object
28
+ def matching? object=nil, &block
24
29
  case object
25
30
  when String
26
31
  object == self.to_s
27
32
  when Symbol
28
33
  object == self.to_s.to_sym
29
34
  when Regexp
30
- !!object.match( self.to_s )
35
+ !!object.match(self.to_s)
31
36
  else
32
37
  super
33
38
  end
@@ -35,12 +40,12 @@ class Numeric
35
40
  end
36
41
 
37
42
  class Regexp
38
- def is_same? object
43
+ def matching? object=nil, &block
39
44
  case object
40
45
  when Class
41
- !!self.match( object.name )
46
+ !!self.match(object.name)
42
47
  when Numeric, String, Symbol
43
- !!self.match( object.to_s )
48
+ !!self.match(object.to_s)
44
49
  else
45
50
  super
46
51
  end
@@ -48,29 +53,29 @@ class Regexp
48
53
  end
49
54
 
50
55
  class String
51
- def is_same? object
56
+ def matching? object=nil, &block
52
57
  case object
53
58
  when Class
54
59
  self == object.name
55
60
  when Numeric, Symbol
56
61
  self == object.to_s
57
62
  when Regexp
58
- !!object.match( self )
63
+ !!object.match(self)
59
64
  else
60
- super
65
+ super object, &block
61
66
  end
62
67
  end
63
68
  end
64
69
 
65
70
  class Symbol
66
- def is_same? object
71
+ def matching? object=nil, &block
67
72
  case object
68
73
  when Class
69
74
  self == object.name.to_sym
70
75
  when Numeric
71
76
  self == object.to_s.to_sym
72
77
  when Regexp
73
- !!object.match( self.to_s )
78
+ !!object.match(self.to_s)
74
79
  when String
75
80
  self == object.to_sym
76
81
  else
@@ -85,40 +90,41 @@ class Array
85
90
  #
86
91
  # @param Object
87
92
  # @return Boolean
88
- def include_same? object
89
- include_same = false
93
+ def elements_matching? object=nil, &block
94
+ matching = false
90
95
  self.each do |value|
91
- if value.is_same? object
92
- include_same = true
96
+ if value.matching? object, &block
97
+ matching = true
93
98
  break
94
99
  end
95
100
  end
96
- include_same
101
+ matching
97
102
  end
98
103
 
99
- # Return Array elements that include same.
104
+ # Return Array elements that are matching.
100
105
  #
101
106
  # @param Object
102
107
  # @return Array<Object> Matching objects.
103
- def including_same object
104
- self.select {|value| value.is_same? object }
108
+ def elements_matching object=nil, &block
109
+ self.select {|value| value.matching?(object, &block) }
105
110
  end
106
111
 
107
112
  end
108
113
 
109
-
110
- # #matching? and #matching support
111
114
  class BasicObject
112
- def matching? *args
113
- is_same? *args
115
+ # For backward compliability
116
+ def is_same? object
117
+ matching? object
114
118
  end
115
119
  end
116
120
 
117
121
  class Array
118
- def matching? *args
119
- include_same? *args
122
+ # For backward compliability
123
+ def include_same? object
124
+ elements_matching? object
120
125
  end
121
- def matching *args
122
- including_same *args
126
+ # For backward compliability
127
+ def including_same object
128
+ elements_matching object
123
129
  end
124
- end
130
+ 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: 0.1.2
4
+ version: 1.0.1
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-21 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec