backports 1.17.1 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/README.rdoc +13 -2
- data/VERSION.yml +3 -3
- data/backports.gemspec +8 -4
- data/lib/backports/1.8.7/enumerator.rb +3 -0
- data/lib/backports/1.9.1/math.rb +25 -0
- data/test/_README +1 -0
- data/test/enumerator_test.rb +7 -0
- data/test/math_test.rb +59 -0
- metadata +14 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Packable --- History
|
2
2
|
|
3
|
+
== Version 1.18.0 - June 19th, 2010
|
4
|
+
|
5
|
+
* Added some features of 1.9.1:
|
6
|
+
|
7
|
+
* Math#log2, Math#log with base
|
8
|
+
|
9
|
+
* Also fixed Enumerator#each in 1.8.6.
|
10
|
+
|
3
11
|
== Version 1.17.0 - May 17th, 2010
|
4
12
|
|
5
13
|
* Added some features of 1.9.2:
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
* Can't remember if you can use Array#sample?
|
4
4
|
* One of your client is stuck with Ruby 1.8.6 but you want to use a gem using some features of 1.8.7?
|
5
|
-
* Yearning to use some of the new cool features in 1.9
|
5
|
+
* Yearning to use some of the new cool features in 1.9.2 while using 1.8.x?
|
6
6
|
|
7
7
|
This gem is for you!
|
8
8
|
|
@@ -79,6 +79,10 @@ Additionally, the following Ruby 1.9 features have been backported:
|
|
79
79
|
* Kernel
|
80
80
|
* +require_relative+
|
81
81
|
|
82
|
+
* Math
|
83
|
+
* +log+ (with base)
|
84
|
+
* +log2+
|
85
|
+
|
82
86
|
* Object
|
83
87
|
* +define_singleton_method+
|
84
88
|
* +public_method+
|
@@ -104,7 +108,7 @@ but since it is only an imitation, it must be required explicitly:
|
|
104
108
|
|
105
109
|
== Ruby 1.9.2
|
106
110
|
|
107
|
-
|
111
|
+
Finally, most of Ruby 1.9.2 features have been backported:
|
108
112
|
|
109
113
|
* Array
|
110
114
|
* <tt>rotate, rotate!</tt>
|
@@ -169,6 +173,13 @@ Libraries have not been backported. I am aware of the following backport gems:
|
|
169
173
|
|
170
174
|
* Let me know of others...
|
171
175
|
|
176
|
+
== Thanks
|
177
|
+
|
178
|
+
Thanks for the bug reports and patches, in particular the repeat offenders:
|
179
|
+
|
180
|
+
* Arto Bendiken ( bendiken[http://github.com/bendiken] )
|
181
|
+
* Roger Pack ( rdp[http://github.com/rdp] )
|
182
|
+
|
172
183
|
= License
|
173
184
|
|
174
185
|
+backports+ is released under the terms of the MIT License, see the included LICENSE file.
|
data/VERSION.yml
CHANGED
data/backports.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{backports}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.18.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marc-Andr\303\251 Lafortune"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-19}
|
13
13
|
s.description = %q{ Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
|
14
14
|
}
|
15
15
|
s.email = %q{github@marc-andre.ca}
|
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
|
|
71
71
|
"lib/backports/1.9.1/integer.rb",
|
72
72
|
"lib/backports/1.9.1/io.rb",
|
73
73
|
"lib/backports/1.9.1/kernel.rb",
|
74
|
+
"lib/backports/1.9.1/math.rb",
|
74
75
|
"lib/backports/1.9.1/string.rb",
|
75
76
|
"lib/backports/1.9.1/symbol.rb",
|
76
77
|
"lib/backports/1.9.2.rb",
|
@@ -97,6 +98,7 @@ Gem::Specification.new do |s|
|
|
97
98
|
"lib/backports/rails/module.rb",
|
98
99
|
"lib/backports/rails/string.rb",
|
99
100
|
"lib/backports/tools.rb",
|
101
|
+
"test/_README",
|
100
102
|
"test/array_test.rb",
|
101
103
|
"test/basic_object_test.rb",
|
102
104
|
"test/binding_test.rb",
|
@@ -104,6 +106,7 @@ Gem::Specification.new do |s|
|
|
104
106
|
"test/enumerator_test.rb",
|
105
107
|
"test/hash_test.rb",
|
106
108
|
"test/kernel_test.rb",
|
109
|
+
"test/math_test.rb",
|
107
110
|
"test/method_missing_test.rb",
|
108
111
|
"test/method_test.rb",
|
109
112
|
"test/module_test.rb",
|
@@ -117,7 +120,7 @@ Gem::Specification.new do |s|
|
|
117
120
|
s.rdoc_options = ["--charset=UTF-8", "--title", "Backports library", "--main", "README.rdoc", "--line-numbers", "--inline-source"]
|
118
121
|
s.require_paths = ["lib"]
|
119
122
|
s.rubyforge_project = %q{backports}
|
120
|
-
s.rubygems_version = %q{1.3.
|
123
|
+
s.rubygems_version = %q{1.3.7}
|
121
124
|
s.summary = %q{Backports of Ruby 1.8.7+ for older ruby.}
|
122
125
|
s.test_files = [
|
123
126
|
"test/array_test.rb",
|
@@ -127,6 +130,7 @@ Gem::Specification.new do |s|
|
|
127
130
|
"test/enumerator_test.rb",
|
128
131
|
"test/hash_test.rb",
|
129
132
|
"test/kernel_test.rb",
|
133
|
+
"test/math_test.rb",
|
130
134
|
"test/method_missing_test.rb",
|
131
135
|
"test/method_test.rb",
|
132
136
|
"test/module_test.rb",
|
@@ -141,7 +145,7 @@ Gem::Specification.new do |s|
|
|
141
145
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
142
146
|
s.specification_version = 3
|
143
147
|
|
144
|
-
if Gem::Version.new(Gem::
|
148
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
145
149
|
else
|
146
150
|
end
|
147
151
|
else
|
@@ -2,6 +2,9 @@ require 'enumerator'
|
|
2
2
|
if (Enumerable::Enumerator rescue false)
|
3
3
|
module Enumerable
|
4
4
|
class Enumerator
|
5
|
+
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerator.html]
|
6
|
+
Backports.make_block_optional self, :each, :test_on => [42].to_enum
|
7
|
+
|
5
8
|
def next
|
6
9
|
require 'generator'
|
7
10
|
@generator ||= Generator.new(self)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Math
|
2
|
+
class << self
|
3
|
+
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
|
4
|
+
unless (log(2, 2) rescue false)
|
5
|
+
def log_with_optional_base(numeric, base = Backports::Undefined)
|
6
|
+
if base.equal?(Backports::Undefined)
|
7
|
+
# Math.log(n) in 1.9.1 no longer accepts string arguments as it
|
8
|
+
# did on 1.8.x, but we won't risk redefining existing behavior
|
9
|
+
# when called with just one argument.
|
10
|
+
log_without_optional_base(numeric)
|
11
|
+
else
|
12
|
+
# Math.log(n, b) in 1.9.1 does not accept string arguments:
|
13
|
+
raise TypeError, "can't convert String into Float" if numeric.is_a?(String) || base.is_a?(String)
|
14
|
+
log_without_optional_base(numeric) / log_without_optional_base(base)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Backports.alias_method_chain self, :log, :optional_base
|
18
|
+
end
|
19
|
+
|
20
|
+
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
|
21
|
+
def log2(numeric)
|
22
|
+
log(numeric, 2)
|
23
|
+
end unless method_defined? :log2
|
24
|
+
end
|
25
|
+
end
|
data/test/_README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
As backports should be ran against RubySpec, tests should ideally be added to RubySpec instead of here...
|
data/test/enumerator_test.rb
CHANGED
@@ -26,6 +26,13 @@ class EnumeratorTest < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
context "#each" do
|
30
|
+
should "should not require block" do
|
31
|
+
assert_nothing_raised { [42].to_enum.each }
|
32
|
+
assert_equal [42], [42].to_enum.each.to_a
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
context "#next" do
|
30
37
|
should "conform to doc" do
|
31
38
|
enum = [10, 20].to_enum
|
data/test/math_test.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MathTest < Test::Unit::TestCase
|
4
|
+
context "Math" do
|
5
|
+
context ".log" do
|
6
|
+
should "accept one argument" do
|
7
|
+
assert_nothing_raised(ArgumentError) { Math.log(1) }
|
8
|
+
end
|
9
|
+
|
10
|
+
should "accept two arguments" do
|
11
|
+
assert_nothing_raised(ArgumentError) { Math.log(2, 2) }
|
12
|
+
end
|
13
|
+
|
14
|
+
should "accept valid arguments" do
|
15
|
+
assert_nothing_raised(TypeError) { Math.log(2, 2) }
|
16
|
+
assert_nothing_raised(TypeError) { Math.log(2, 2.0) }
|
17
|
+
end
|
18
|
+
|
19
|
+
should "reject invalid arguments" do
|
20
|
+
assert_raises(TypeError) { Math.log(2, nil) }
|
21
|
+
assert_raises(TypeError) { Math.log(2, "2") }
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return the correct value" do
|
25
|
+
assert_equal 0.0, Math.log(1)
|
26
|
+
assert_equal 1.0, Math.log(Math::E)
|
27
|
+
assert_equal 3.0, Math.log(Math::E**3)
|
28
|
+
assert_equal 3.0, Math.log(8, 2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context ".log2" do
|
33
|
+
should "be defined" do
|
34
|
+
assert_respond_to Math, :log2
|
35
|
+
end
|
36
|
+
|
37
|
+
should "accept one argument" do
|
38
|
+
assert_nothing_raised(ArgumentError) { Math.log2(1) }
|
39
|
+
end
|
40
|
+
|
41
|
+
should "accept valid arguments" do
|
42
|
+
assert_nothing_raised(TypeError) { Math.log2(1) }
|
43
|
+
assert_nothing_raised(TypeError) { Math.log2(1.0) }
|
44
|
+
end
|
45
|
+
|
46
|
+
should "reject invalid arguments" do
|
47
|
+
assert_raises(TypeError) { Math.log2(nil) }
|
48
|
+
assert_raises(TypeError) { Math.log2("1") }
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return the correct value" do
|
52
|
+
assert_equal 0.0, Math.log2(1)
|
53
|
+
assert_equal 1.0, Math.log2(2)
|
54
|
+
assert_equal 15.0, Math.log2(32768)
|
55
|
+
assert_equal 16.0, Math.log2(65536)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 95
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 18
|
9
|
+
- 0
|
10
|
+
version: 1.18.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "Marc-Andr\xC3\xA9 Lafortune"
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-19 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -81,6 +82,7 @@ files:
|
|
81
82
|
- lib/backports/1.9.1/integer.rb
|
82
83
|
- lib/backports/1.9.1/io.rb
|
83
84
|
- lib/backports/1.9.1/kernel.rb
|
85
|
+
- lib/backports/1.9.1/math.rb
|
84
86
|
- lib/backports/1.9.1/string.rb
|
85
87
|
- lib/backports/1.9.1/symbol.rb
|
86
88
|
- lib/backports/1.9.2.rb
|
@@ -107,6 +109,7 @@ files:
|
|
107
109
|
- lib/backports/rails/module.rb
|
108
110
|
- lib/backports/rails/string.rb
|
109
111
|
- lib/backports/tools.rb
|
112
|
+
- test/_README
|
110
113
|
- test/array_test.rb
|
111
114
|
- test/basic_object_test.rb
|
112
115
|
- test/binding_test.rb
|
@@ -114,6 +117,7 @@ files:
|
|
114
117
|
- test/enumerator_test.rb
|
115
118
|
- test/hash_test.rb
|
116
119
|
- test/kernel_test.rb
|
120
|
+
- test/math_test.rb
|
117
121
|
- test/method_missing_test.rb
|
118
122
|
- test/method_test.rb
|
119
123
|
- test/module_test.rb
|
@@ -138,23 +142,27 @@ rdoc_options:
|
|
138
142
|
require_paths:
|
139
143
|
- lib
|
140
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
141
146
|
requirements:
|
142
147
|
- - ">="
|
143
148
|
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
144
150
|
segments:
|
145
151
|
- 0
|
146
152
|
version: "0"
|
147
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
148
155
|
requirements:
|
149
156
|
- - ">="
|
150
157
|
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
151
159
|
segments:
|
152
160
|
- 0
|
153
161
|
version: "0"
|
154
162
|
requirements: []
|
155
163
|
|
156
164
|
rubyforge_project: backports
|
157
|
-
rubygems_version: 1.3.
|
165
|
+
rubygems_version: 1.3.7
|
158
166
|
signing_key:
|
159
167
|
specification_version: 3
|
160
168
|
summary: Backports of Ruby 1.8.7+ for older ruby.
|
@@ -166,6 +174,7 @@ test_files:
|
|
166
174
|
- test/enumerator_test.rb
|
167
175
|
- test/hash_test.rb
|
168
176
|
- test/kernel_test.rb
|
177
|
+
- test/math_test.rb
|
169
178
|
- test/method_missing_test.rb
|
170
179
|
- test/method_test.rb
|
171
180
|
- test/module_test.rb
|