is_same 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ class Array
2
+ # Check if any elements of an Array is same as argument.
3
+ #
4
+ # @param Object
5
+ # @return Boolean
6
+ def elements_matching?(object=nil, &block)
7
+ self.any? {|value| value.matching?(object, &block) }
8
+ end
9
+
10
+ # Return Array elements that are matching.
11
+ #
12
+ # @param Object
13
+ # @return Array<Object> Matching objects.
14
+ def elements_matching(object=nil, &block)
15
+ self.select {|value| value.matching?(object, &block) }
16
+ end
17
+
18
+ end
@@ -0,0 +1,10 @@
1
+ class Array
2
+ # For backward compliability
3
+ def include_same?(object)
4
+ elements_matching? object
5
+ end
6
+ # For backward compliability
7
+ def including_same(object)
8
+ elements_matching object
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class Object
2
+ # For backward compliability
3
+ def is_same?(object)
4
+ matching? object
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ class Class
2
+ def matching?(object=nil, &block)
3
+ case object
4
+ when String
5
+ object == self.name
6
+ when Symbol
7
+ object == self.name.to_sym
8
+ when Regexp
9
+ !!object.match(self.name)
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class Numeric
2
+ def matching?(object=nil, &block)
3
+ case object
4
+ when String
5
+ object == self.to_s
6
+ when Symbol
7
+ object == self.to_s.to_sym
8
+ when Regexp
9
+ !!object.match(self.to_s)
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ class Object
2
+ def matching?(object=nil, &block)
3
+ if object.is_a?(Proc) or block
4
+ object ||= block
5
+ object.call(self)
6
+ else
7
+ self == object
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class Regexp
2
+ def matching?(object=nil, &block)
3
+ case object
4
+ when Class
5
+ !!self.match(object.name)
6
+ when Numeric, String, Symbol
7
+ !!self.match(object.to_s)
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class String
2
+ def matching?(object=nil, &block)
3
+ case object
4
+ when Class
5
+ self == object.name
6
+ when Numeric, Symbol
7
+ self == object.to_s
8
+ when Regexp
9
+ !!object.match(self)
10
+ else
11
+ super object, &block
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ class Symbol
2
+ def matching?(object=nil, &block)
3
+ case object
4
+ when Class
5
+ self == object.name.to_sym
6
+ when Numeric
7
+ self == object.to_s.to_sym
8
+ when Regexp
9
+ !!object.match(self.to_s)
10
+ when String
11
+ self == object.to_sym
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
data/lib/is_same.rb CHANGED
@@ -1 +1,10 @@
1
- require 'is_same/core_ext/core_ext'
1
+ path = 'is_same/core_ext'
2
+ classes = [:object, :array, :class, :numeric, :regexp, :string, :symbol]
3
+
4
+ classes.each do |klass|
5
+ require "#{path}/#{klass}"
6
+ end
7
+
8
+
9
+ require "#{path}/backward_compliability/object"
10
+ require "#{path}/backward_compliability/array"
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.5
4
+ version: 1.0.6
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-30 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard
@@ -68,8 +68,16 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - README.md
70
70
  - Gemfile
71
- - lib/is_same/core_ext/core_ext.rb
72
71
  - lib/is_same.rb
72
+ - lib/is_same/core_ext/regexp.rb
73
+ - lib/is_same/core_ext/string.rb
74
+ - lib/is_same/core_ext/array.rb
75
+ - lib/is_same/core_ext/symbol.rb
76
+ - lib/is_same/core_ext/class.rb
77
+ - lib/is_same/core_ext/object.rb
78
+ - lib/is_same/core_ext/backward_compliability/array.rb
79
+ - lib/is_same/core_ext/backward_compliability/object.rb
80
+ - lib/is_same/core_ext/numeric.rb
73
81
  homepage: https://github.com/tione/is_same
74
82
  licenses: []
75
83
  post_install_message:
@@ -1,123 +0,0 @@
1
- class Object
2
- def matching? object=nil, &block
3
- if object.is_a?(Proc) or block
4
- object ||= block
5
- object.call(self)
6
- else
7
- self == object
8
- end
9
- end
10
- end
11
-
12
- class Class
13
- def matching? object=nil, &block
14
- case object
15
- when String
16
- object == self.name
17
- when Symbol
18
- object == self.name.to_sym
19
- when Regexp
20
- !!object.match(self.name)
21
- else
22
- super
23
- end
24
- end
25
- end
26
-
27
- class Numeric
28
- def matching? object=nil, &block
29
- case object
30
- when String
31
- object == self.to_s
32
- when Symbol
33
- object == self.to_s.to_sym
34
- when Regexp
35
- !!object.match(self.to_s)
36
- else
37
- super
38
- end
39
- end
40
- end
41
-
42
- class Regexp
43
- def matching? object=nil, &block
44
- case object
45
- when Class
46
- !!self.match(object.name)
47
- when Numeric, String, Symbol
48
- !!self.match(object.to_s)
49
- else
50
- super
51
- end
52
- end
53
- end
54
-
55
- class String
56
- def matching? object=nil, &block
57
- case object
58
- when Class
59
- self == object.name
60
- when Numeric, Symbol
61
- self == object.to_s
62
- when Regexp
63
- !!object.match(self)
64
- else
65
- super object, &block
66
- end
67
- end
68
- end
69
-
70
- class Symbol
71
- def matching? object=nil, &block
72
- case object
73
- when Class
74
- self == object.name.to_sym
75
- when Numeric
76
- self == object.to_s.to_sym
77
- when Regexp
78
- !!object.match(self.to_s)
79
- when String
80
- self == object.to_sym
81
- else
82
- super
83
- end
84
-
85
- end
86
- end
87
-
88
- class Array
89
- # Check if any elements of an Array is same as argument.
90
- #
91
- # @param Object
92
- # @return Boolean
93
- def elements_matching? object=nil, &block
94
- self.any? {|value| value.matching?(object, &block) }
95
- end
96
-
97
- # Return Array elements that are matching.
98
- #
99
- # @param Object
100
- # @return Array<Object> Matching objects.
101
- def elements_matching object=nil, &block
102
- self.select {|value| value.matching?(object, &block) }
103
- end
104
-
105
- end
106
-
107
- class Object
108
- # For backward compliability
109
- def is_same? object
110
- matching? object
111
- end
112
- end
113
-
114
- class Array
115
- # For backward compliability
116
- def include_same? object
117
- elements_matching? object
118
- end
119
- # For backward compliability
120
- def including_same object
121
- elements_matching object
122
- end
123
- end