is_same 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/README.rdoc +5 -2
- data/lib/is_same/core_ext.rb +55 -29
- metadata +38 -3
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -27,7 +27,10 @@ Supports Regexp.
|
|
27
27
|
String.is_same?(/tring/) # Same as: /tring/.match(String.name)
|
28
28
|
"String".is_same?(String) # Same as: "String" == String.name
|
29
29
|
|
30
|
-
"1".is_same?(1) # Same as: 1
|
31
|
-
0.001.is_same?("0.001") # Same as: 0.001 == "0.001"
|
30
|
+
"1".is_same?(1) # Same as: "1" == 1.to_s
|
31
|
+
0.001.is_same?("0.001") # Same as: 0.001.to_s == "0.001"
|
32
32
|
123456.is_same?(/234/) # Same as: /234/.match(123456.to_s)
|
33
33
|
|
34
|
+
|
35
|
+
More examples can be seen in Rspec tests:
|
36
|
+
* https://github.com/tione/is_same/tree/master/spec
|
data/lib/is_same/core_ext.rb
CHANGED
@@ -1,55 +1,81 @@
|
|
1
|
-
class
|
1
|
+
class BasicObject
|
2
2
|
def is_same?(object)
|
3
|
-
|
3
|
+
self == object
|
4
4
|
end
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
|
+
class Class
|
7
8
|
def is_same?(object)
|
8
9
|
case object
|
9
|
-
when String
|
10
|
-
|
11
|
-
when
|
12
|
-
|
10
|
+
when String
|
11
|
+
object == self.name
|
12
|
+
when Symbol
|
13
|
+
object == self.name.to_sym
|
14
|
+
when Regexp
|
15
|
+
!!object.match(self.name)
|
16
|
+
else
|
17
|
+
super
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
16
|
-
|
21
|
+
|
22
|
+
class Numeric
|
17
23
|
def is_same?(object)
|
18
24
|
case object
|
19
|
-
when
|
20
|
-
|
25
|
+
when String
|
26
|
+
object == self.to_s
|
27
|
+
when Symbol
|
28
|
+
object == self.to_s.to_sym
|
29
|
+
when Regexp
|
30
|
+
!!object.match(self.to_s)
|
31
|
+
else
|
32
|
+
super
|
21
33
|
end
|
22
34
|
end
|
23
35
|
end
|
24
|
-
|
36
|
+
|
37
|
+
class Regexp
|
25
38
|
def is_same?(object)
|
26
39
|
case object
|
27
|
-
when Class
|
28
|
-
|
40
|
+
when Class
|
41
|
+
!!self.match(object.name)
|
42
|
+
when Numeric, String, Symbol
|
43
|
+
!!self.match(object.to_s)
|
44
|
+
else
|
45
|
+
super
|
29
46
|
end
|
30
47
|
end
|
31
48
|
end
|
32
|
-
|
49
|
+
|
50
|
+
class String
|
33
51
|
def is_same?(object)
|
34
52
|
case object
|
35
|
-
when
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
when object.respond_to?(:to_i); return self == object.to_i
|
44
|
-
else; return self.to_s.is_same?(object)
|
53
|
+
when Class
|
54
|
+
self == object.name
|
55
|
+
when Numeric, Symbol
|
56
|
+
self == object.to_s
|
57
|
+
when Regexp
|
58
|
+
!!object.match(self)
|
59
|
+
else
|
60
|
+
super
|
45
61
|
end
|
46
62
|
end
|
47
63
|
end
|
48
|
-
|
64
|
+
|
65
|
+
class Symbol
|
49
66
|
def is_same?(object)
|
50
|
-
case
|
51
|
-
when
|
52
|
-
|
67
|
+
case object
|
68
|
+
when Class
|
69
|
+
self == object.name.to_sym
|
70
|
+
when Numeric
|
71
|
+
self == object.to_s.to_sym
|
72
|
+
when Regexp
|
73
|
+
!!object.match(self.to_s)
|
74
|
+
when String
|
75
|
+
self == object.to_sym
|
76
|
+
else
|
77
|
+
super
|
53
78
|
end
|
79
|
+
|
54
80
|
end
|
55
|
-
end
|
81
|
+
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.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,41 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-02-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &23805580 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *23805580
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-core
|
27
|
+
requirement: &23805120 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *23805120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &23804700 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *23804700
|
14
47
|
description: To evaluate if different kind of objects have the same value or meaning,
|
15
48
|
comparing objects without the need to worry about their type. Supports regexp.
|
16
49
|
email: margus@tione.eu
|
@@ -19,6 +52,7 @@ extensions: []
|
|
19
52
|
extra_rdoc_files: []
|
20
53
|
files:
|
21
54
|
- README.rdoc
|
55
|
+
- Gemfile
|
22
56
|
- lib/is_same/core_ext.rb
|
23
57
|
- lib/is_same.rb
|
24
58
|
homepage: https://github.com/tione/is_same
|
@@ -46,3 +80,4 @@ signing_key:
|
|
46
80
|
specification_version: 3
|
47
81
|
summary: Compare objects without the need to worry about their type.
|
48
82
|
test_files: []
|
83
|
+
has_rdoc:
|