is_same 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ == Installation
2
+
3
+ gem install is_same
4
+
5
+
6
+ == Why?
7
+
8
+ To evulate if different kind of objects have the same value or meaning. Supports Regexp.
9
+
10
+
11
+ == Usage
12
+
13
+ include 'is_same'
14
+
15
+
16
+ # These evulate to False:
17
+
18
+ "String".is_same?("tring") # Same as: "String" == "tring"
19
+ Object.new.is_same(Object.new) # Same as: Object.new == Object.new
20
+
21
+
22
+ # These evulate to True:
23
+
24
+ :String.is_same?("String") # Same as: :String.to_s == "String"
25
+ String.is_same?(/tring/) # Same as: /tring/.match(String.name)
26
+ "String".is_same?(String) # Same as: "String" == String.name
27
+
28
+ "1".is_same?(1) # Same as: 1.to_i == 1
29
+ 0.001.is_same?("0.001") # Same as: 0.001 == "0.001".to_f
30
+ 123456.is_same?(/234/) # Same as: /234/.match(123456.to_s)
@@ -0,0 +1,55 @@
1
+ class Object
2
+ def is_same?(object)
3
+ return self <=> object
4
+ end
5
+ end
6
+ class String
7
+ def is_same?(object)
8
+ case object
9
+ when String; return self == object
10
+ when Regexp; return object.match(self)
11
+ when Class; return object.is_same?(self)
12
+ else; return self == object.to_s
13
+ end
14
+ end
15
+ end
16
+ class Symbol
17
+ def is_same?(object)
18
+ case object
19
+ when Symbol; return self == object
20
+ else; self.to_s.is_same?(object)
21
+ end
22
+ end
23
+ end
24
+ class Class
25
+ def is_same?(object)
26
+ case object
27
+ when Class; return self == object
28
+ else; return self.name.is_same?(object)
29
+ end
30
+ end
31
+ end
32
+ class Regexp
33
+ def is_same?(object)
34
+ case object
35
+ when Regexp; return object.match(self.to_s)
36
+ else; return object.is_same?(self)
37
+ end
38
+ end
39
+ end
40
+ class Integer
41
+ def is_same?(object)
42
+ case
43
+ when object.respond_to?(:to_i); return self == object.to_i
44
+ else; return self.to_s.is_same?(object)
45
+ end
46
+ end
47
+ end
48
+ class Float
49
+ def is_same?(object)
50
+ case
51
+ when object.respond_to?(:to_f); return self == object.to_f
52
+ else; return self.to_s.is_same?(object)
53
+ end
54
+ end
55
+ end
data/lib/is_same.rb ADDED
@@ -0,0 +1 @@
1
+ include 'is_same/core_ext'
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_same
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - "Margus P\xC3\xA4rt"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-12 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: To evulate if different kind of objects have the same value. Supports Regexp.
22
+ email: margus@tione.eu
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.rdoc
31
+ - lib/is_same/core_ext.rb
32
+ - lib/is_same.rb
33
+ has_rdoc: true
34
+ homepage: https://github.com/tione/is_same
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 1
49
+ - 9
50
+ - 2
51
+ version: 1.9.2
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Introduces is_same? method to compare if different types of objects have the same meaning.
67
+ test_files: []
68
+