ruby-version 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ number matching. Usage is simple:
6
6
 
7
7
  require "ruby-version"
8
8
 
9
- Ruby::Version > 1.8.7
9
+ Ruby::Version > "1.8.7"
10
10
  # will return true for 1.9.2 and false for 1.8.3
11
11
 
12
12
  Contributing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/ruby-version.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # encoding: utf-8
2
2
  # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
3
 
4
- require "hash-utils/numeric"
4
+ require "hash-utils/numeric" # >= 0.16.0
5
+ require "hash-utils/object" # >= 0.17.0
6
+ require "lookup-hash"
5
7
 
6
8
  ##
7
9
  # Outer wrapper for the {Ruby::Version} module.
@@ -23,6 +25,12 @@ module Ruby
23
25
 
24
26
  VERSION = RUBY_VERSION.freeze
25
27
 
28
+ ##
29
+ # Holds comparign cache.
30
+ #
31
+
32
+ @cache
33
+
26
34
  ##
27
35
  # Higher or equal operator.
28
36
  #
@@ -31,7 +39,9 @@ module Ruby
31
39
  #
32
40
 
33
41
  def self.>=(value)
34
- __compare(value, false, true, true)
42
+ __cache(:">=", value) do
43
+ __compare(value, false, true, true)
44
+ end
35
45
  end
36
46
 
37
47
  ##
@@ -42,7 +52,9 @@ module Ruby
42
52
  #
43
53
 
44
54
  def self.<=(value)
45
- __compare(value, true, false, true)
55
+ __cache(:"<=", value) do
56
+ __compare(value, true, false, true)
57
+ end
46
58
  end
47
59
 
48
60
  ##
@@ -53,7 +65,9 @@ module Ruby
53
65
  #
54
66
 
55
67
  def self.<(value)
56
- __compare(value, true, false, false)
68
+ __cache(:<, value) do
69
+ __compare(value, true, false, false)
70
+ end
57
71
  end
58
72
 
59
73
  ##
@@ -64,7 +78,9 @@ module Ruby
64
78
  #
65
79
 
66
80
  def self.>(value)
67
- __compare(value, false, true, false)
81
+ __cache(:>, value) do
82
+ __compare(value, false, true, false)
83
+ end
68
84
  end
69
85
 
70
86
  ##
@@ -75,7 +91,9 @@ module Ruby
75
91
  #
76
92
 
77
93
  def self.==(value)
78
- __compare(value, false, false, true)
94
+ __cache(:"==", value) do
95
+ __compare(value, false, false, true)
96
+ end
79
97
  end
80
98
 
81
99
  ##
@@ -86,7 +104,9 @@ module Ruby
86
104
  #
87
105
 
88
106
  def self.compare(value)
89
- __compare(value, -1, 1, 0)
107
+ __cache(:compare, value) do
108
+ __compare(value, -1, 1, 0)
109
+ end
90
110
  end
91
111
 
92
112
  ##
@@ -114,7 +134,7 @@ module Ruby
114
134
 
115
135
  private
116
136
  def self.__compare(value, lower, higher, equal)
117
- if not value.kind_of? Array
137
+ if not value.array?
118
138
  value = self.broke(value.to_s)
119
139
  end
120
140
 
@@ -130,6 +150,25 @@ module Ruby
130
150
  return equal
131
151
  end
132
152
 
153
+ ##
154
+ # Universal cache routine.
155
+ #
156
+
157
+ private
158
+ def self.__cache(operation, value, &block)
159
+ value = value.to_sym if value.string?
160
+
161
+ if @cache.nil?
162
+ @cache = Hash::new { |dict, key| dict[key] = { } }
163
+ end
164
+
165
+ if not @cache[operation].has_key? value
166
+ @cache[operation][value] = block.call()
167
+ end
168
+
169
+ @cache[operation][value]
170
+ end
171
+
133
172
  end
134
173
  end
135
174
 
data/ruby-version.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-version}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Martin Kozák}]
12
- s.date = %q{2011-06-23}
12
+ s.date = %q{2011-06-24}
13
13
  s.email = %q{martinkozak@martinkozak.net}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby-version
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Martin Koz\xC3\xA1k"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-23 00:00:00 Z
13
+ date: 2011-06-24 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hash-utils
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- hash: -114962964112072926
92
+ hash: 2910567639551139310
93
93
  segments:
94
94
  - 0
95
95
  version: "0"