backports 1.18.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/backports.gemspec +4 -5
- data/lib/backports/1.8.7/array.rb +5 -4
- data/lib/backports/1.8.7/enumerable.rb +35 -19
- data/lib/backports/1.8.7/kernel.rb +13 -11
- data/lib/backports/1.8.7/string.rb +17 -17
- data/lib/backports/1.8.8/array.rb +1 -1
- data/lib/backports/1.8.8/enumerable.rb +2 -2
- data/lib/backports/1.8.8/io.rb +1 -1
- data/lib/backports/1.8.8/regexp.rb +7 -3
- data/lib/backports/1.9.2/array.rb +9 -7
- data/lib/backports/tools.rb +9 -4
- metadata +10 -6
- data/lib/backports/1.9.2/method.rb +0 -101
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 = "
|
8
|
+
s.version = "2.0.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{
|
12
|
+
s.date = %q{2011-03-04}
|
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}
|
@@ -82,7 +82,6 @@ Gem::Specification.new do |s|
|
|
82
82
|
"lib/backports/1.9.2/hash.rb",
|
83
83
|
"lib/backports/1.9.2/kernel.rb",
|
84
84
|
"lib/backports/1.9.2/match_data.rb",
|
85
|
-
"lib/backports/1.9.2/method.rb",
|
86
85
|
"lib/backports/1.9.2/random.rb",
|
87
86
|
"lib/backports/1.9.2/random/MT19937.rb",
|
88
87
|
"lib/backports/1.9.2/random/bits_and_bytes.rb",
|
@@ -120,7 +119,7 @@ Gem::Specification.new do |s|
|
|
120
119
|
s.rdoc_options = ["--charset=UTF-8", "--title", "Backports library", "--main", "README.rdoc", "--line-numbers", "--inline-source"]
|
121
120
|
s.require_paths = ["lib"]
|
122
121
|
s.rubyforge_project = %q{backports}
|
123
|
-
s.rubygems_version = %q{1.3.
|
122
|
+
s.rubygems_version = %q{1.3.7}
|
124
123
|
s.summary = %q{Backports of Ruby 1.8.7+ for older ruby.}
|
125
124
|
s.test_files = [
|
126
125
|
"test/array_test.rb",
|
@@ -145,7 +144,7 @@ Gem::Specification.new do |s|
|
|
145
144
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
146
145
|
s.specification_version = 3
|
147
146
|
|
148
|
-
if Gem::Version.new(Gem::
|
147
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
149
148
|
else
|
150
149
|
end
|
151
150
|
else
|
@@ -19,13 +19,13 @@ class Array
|
|
19
19
|
end unless method_defined? :combination
|
20
20
|
|
21
21
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
22
|
-
def cycle(n = nil
|
22
|
+
def cycle(n = nil)
|
23
23
|
return to_enum(:cycle, n) unless block_given?
|
24
24
|
if n.nil?
|
25
|
-
|
25
|
+
each{|e| yield e } until false
|
26
26
|
else
|
27
27
|
n = Backports.coerce_to_int(n)
|
28
|
-
n.times{each
|
28
|
+
n.times{each{|e| yield e }}
|
29
29
|
end
|
30
30
|
nil
|
31
31
|
end unless method_defined? :cycle
|
@@ -91,7 +91,7 @@ class Array
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
94
|
-
def permutation(num = Backports::Undefined
|
94
|
+
def permutation(num = Backports::Undefined)
|
95
95
|
return to_enum(:permutation, num) unless block_given?
|
96
96
|
num = num.equal?(Backports::Undefined) ?
|
97
97
|
size :
|
@@ -197,6 +197,7 @@ class Array
|
|
197
197
|
|
198
198
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
199
199
|
def shuffle!
|
200
|
+
raise TypeError, "can't modify frozen array" if frozen?
|
200
201
|
size.times do |i|
|
201
202
|
r = i + Kernel.rand(size - i)
|
202
203
|
self[i], self[r] = self[r], self[i]
|
@@ -14,18 +14,24 @@ module Enumerable
|
|
14
14
|
end unless method_defined? :count
|
15
15
|
|
16
16
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
17
|
-
def cycle(n = nil
|
17
|
+
def cycle(n = nil)
|
18
18
|
return to_enum(:cycle, n) unless block_given?
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
cache
|
25
|
-
|
19
|
+
if n.nil?
|
20
|
+
each{|e| yield e } until false
|
21
|
+
else
|
22
|
+
n = Backports.coerce_to_int(n)
|
23
|
+
if n >= 1
|
24
|
+
cache = []
|
25
|
+
each do |elem|
|
26
|
+
cache << elem
|
27
|
+
yield elem
|
28
|
+
end
|
29
|
+
(n-1).times do
|
30
|
+
cache.each{|e| yield e }
|
31
|
+
end
|
26
32
|
end
|
27
|
-
cache.cycle(n-1, &block)
|
28
33
|
end
|
34
|
+
nil
|
29
35
|
end unless method_defined? :cycle
|
30
36
|
|
31
37
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
@@ -43,7 +49,7 @@ module Enumerable
|
|
43
49
|
end unless method_defined? :drop
|
44
50
|
|
45
51
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
46
|
-
def drop_while
|
52
|
+
def drop_while
|
47
53
|
return to_enum(:drop_while) unless block_given?
|
48
54
|
ary = []
|
49
55
|
dropping = true
|
@@ -55,7 +61,7 @@ module Enumerable
|
|
55
61
|
|
56
62
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
57
63
|
if instance_method(:each_with_index).arity.zero?
|
58
|
-
def each_with_index_with_optional_args_and_block(*args
|
64
|
+
def each_with_index_with_optional_args_and_block(*args)
|
59
65
|
return to_enum(:each_with_index, *args) unless block_given?
|
60
66
|
idx = 0
|
61
67
|
each(*args) { |o| yield(o, idx); idx += 1 }
|
@@ -119,15 +125,25 @@ module Enumerable
|
|
119
125
|
end
|
120
126
|
|
121
127
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
122
|
-
def max_by
|
128
|
+
def max_by
|
123
129
|
return to_enum(:max_by) unless block_given?
|
124
|
-
|
130
|
+
max_object, max_result = nil, MOST_EXTREME_OBJECT_EVER
|
131
|
+
each do |object|
|
132
|
+
result = yield object
|
133
|
+
max_object, max_result = object, result if max_result < result
|
134
|
+
end
|
135
|
+
max_object
|
125
136
|
end unless method_defined? :max_by
|
126
137
|
|
127
138
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
128
|
-
def min_by
|
139
|
+
def min_by
|
129
140
|
return to_enum(:min_by) unless block_given?
|
130
|
-
|
141
|
+
min_object, min_result = nil, MOST_EXTREME_OBJECT_EVER
|
142
|
+
each do |object|
|
143
|
+
result = yield object
|
144
|
+
min_object, min_result = object, result if min_result > result
|
145
|
+
end
|
146
|
+
min_object
|
131
147
|
end unless method_defined? :min_by
|
132
148
|
|
133
149
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
@@ -148,7 +164,7 @@ module Enumerable
|
|
148
164
|
end unless method_defined? :minmax
|
149
165
|
|
150
166
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
151
|
-
def minmax_by
|
167
|
+
def minmax_by
|
152
168
|
return to_enum(:minmax_by) unless block_given?
|
153
169
|
min_object, min_result = nil, MOST_EXTREME_OBJECT_EVER
|
154
170
|
max_object, max_result = nil, MOST_EXTREME_OBJECT_EVER
|
@@ -166,7 +182,7 @@ module Enumerable
|
|
166
182
|
end unless method_defined? :none?
|
167
183
|
|
168
184
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
169
|
-
def one?
|
185
|
+
def one?
|
170
186
|
found_one = false
|
171
187
|
if block_given?
|
172
188
|
each do |o|
|
@@ -189,10 +205,10 @@ module Enumerable
|
|
189
205
|
Backports.alias_method self, :reduce, :inject
|
190
206
|
|
191
207
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
192
|
-
def reverse_each
|
208
|
+
def reverse_each
|
193
209
|
return to_enum(:reverse_each) unless block_given?
|
194
210
|
# There is no other way then to convert to an array first... see 1.9's source.
|
195
|
-
to_a.reverse_each
|
211
|
+
to_a.reverse_each{|e| yield e}
|
196
212
|
self
|
197
213
|
end unless method_defined? :reverse_each
|
198
214
|
|
@@ -13,10 +13,19 @@ module Kernel
|
|
13
13
|
send(:"temporary method for instance_exec", *arg)
|
14
14
|
end unless method_defined? :instance_exec
|
15
15
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
16
|
+
# Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
|
17
|
+
def tap
|
18
|
+
yield self
|
19
|
+
self
|
20
|
+
end unless method_defined? :tap
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# Loop. Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
|
25
|
+
unless Object.const_defined? :StopIteration
|
26
|
+
class StopIteration < IndexError; end
|
19
27
|
|
28
|
+
module Kernel
|
20
29
|
def loop_with_stop_iteration(&block)
|
21
30
|
loop_without_stop_iteration(&block)
|
22
31
|
rescue StopIteration
|
@@ -24,11 +33,4 @@ module Kernel
|
|
24
33
|
end
|
25
34
|
Backports.alias_method_chain self, :loop, :stop_iteration
|
26
35
|
end
|
27
|
-
|
28
|
-
# Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
|
29
|
-
def tap
|
30
|
-
yield self
|
31
|
-
self
|
32
|
-
end unless method_defined? :tap
|
33
|
-
|
34
|
-
end
|
36
|
+
end
|
@@ -15,9 +15,9 @@ class String
|
|
15
15
|
|
16
16
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
|
17
17
|
unless method_defined? :each_char
|
18
|
-
def each_char
|
18
|
+
def each_char
|
19
19
|
return to_enum(:each_char) unless block_given?
|
20
|
-
scan(
|
20
|
+
scan(/./) {|c| yield c}
|
21
21
|
end
|
22
22
|
|
23
23
|
Backports.alias_method self, :chars, :each_char
|
@@ -27,18 +27,18 @@ class String
|
|
27
27
|
|
28
28
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
|
29
29
|
def end_with?(*suffixes)
|
30
|
-
suffixes.
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
suffixes.any? do |suffix|
|
31
|
+
if suffix.respond_to? :to_str
|
32
|
+
suffix = suffix.to_str
|
33
|
+
self[-suffix.length, suffix.length] == suffix
|
34
|
+
end
|
34
35
|
end
|
35
|
-
false
|
36
36
|
end unless method_defined? :end_with?
|
37
37
|
|
38
38
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
|
39
39
|
unless ("check partition".partition(" ") rescue false)
|
40
|
-
def partition_with_new_meaning(pattern = Backports::Undefined
|
41
|
-
return partition_without_new_meaning
|
40
|
+
def partition_with_new_meaning(pattern = Backports::Undefined)
|
41
|
+
return partition_without_new_meaning{|c| yield c} if pattern == Backports::Undefined
|
42
42
|
pattern = Backports.coerce_to(pattern, String, :to_str) unless pattern.is_a? Regexp
|
43
43
|
i = index(pattern)
|
44
44
|
return [self, "", ""] unless i
|
@@ -70,21 +70,21 @@ class String
|
|
70
70
|
|
71
71
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
|
72
72
|
def start_with?(*prefixes)
|
73
|
-
prefixes.
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
prefixes.any? do |prefix|
|
74
|
+
if prefix.respond_to? :to_str
|
75
|
+
prefix = prefix.to_str
|
76
|
+
self[0, prefix.length] == prefix
|
77
|
+
end
|
77
78
|
end
|
78
|
-
false
|
79
79
|
end unless method_defined? :start_with?
|
80
80
|
|
81
81
|
# Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
|
82
82
|
unless ("abc".upto("def", true) rescue false)
|
83
|
-
def upto_with_exclusive(to, excl=false
|
84
|
-
return upto_without_exclusive(to
|
83
|
+
def upto_with_exclusive(to, excl=false)
|
84
|
+
return upto_without_exclusive(to){|s| yield s} if block_given? && !excl
|
85
85
|
enum = Range.new(self, to, excl).to_enum
|
86
86
|
return enum unless block_given?
|
87
|
-
enum.each
|
87
|
+
enum.each{|s| yield s}
|
88
88
|
self
|
89
89
|
end
|
90
90
|
Backports.alias_method_chain self, :upto, :exclusive
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Array
|
2
2
|
# Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
3
3
|
class << self
|
4
|
-
def
|
4
|
+
def try_convert(obj)
|
5
5
|
return nil unless obj.respond_to?(:to_ary)
|
6
6
|
Backports.coerce_to_ary(obj)
|
7
7
|
end unless method_defined? :try_convert
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Enumerable
|
2
2
|
# Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
|
3
|
-
def each_with_object(memo
|
3
|
+
def each_with_object(memo)
|
4
4
|
return to_enum(:each_with_object, memo) unless block_given?
|
5
|
-
each {|obj|
|
5
|
+
each {|obj| yield obj, memo}
|
6
6
|
memo
|
7
7
|
end unless method_defined? :each_with_object
|
8
8
|
end
|
data/lib/backports/1.8.8/io.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class IO
|
2
2
|
# Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/IO.html]
|
3
3
|
class << self
|
4
|
-
def
|
4
|
+
def try_convert(obj)
|
5
5
|
return nil unless obj.respond_to?(:to_io)
|
6
6
|
Backports.coerce_to(obj, IO, :to_io)
|
7
7
|
end unless method_defined? :try_convert
|
@@ -1,9 +1,13 @@
|
|
1
1
|
class Regexp
|
2
2
|
# Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
|
3
3
|
class << self
|
4
|
-
def
|
5
|
-
|
6
|
-
|
4
|
+
def try_convert(obj)
|
5
|
+
case
|
6
|
+
when obj.is_a?(Regexp)
|
7
|
+
obj
|
8
|
+
when obj.respond_to?(:to_regexp)
|
9
|
+
Backports.coerce_to(obj, Regexp, :to_regexp)
|
10
|
+
end
|
7
11
|
end unless method_defined? :try_convert
|
8
12
|
end
|
9
13
|
end
|
@@ -29,7 +29,7 @@ class Array
|
|
29
29
|
|
30
30
|
# Note: Combinations are not yielded in the same order as MRI.
|
31
31
|
# This is not a bug; the spec states that the order is implementation dependent
|
32
|
-
def repeated_combination(num
|
32
|
+
def repeated_combination(num)
|
33
33
|
return to_enum(:repeated_combination, num) unless block_given?
|
34
34
|
num = Backports.coerce_to_int(num)
|
35
35
|
if num <= 0
|
@@ -47,7 +47,7 @@ class Array
|
|
47
47
|
|
48
48
|
# Note: Permutations are not yielded in the same order as MRI.
|
49
49
|
# This is not a bug; the spec states that the order is implementation dependent
|
50
|
-
def repeated_permutation(num
|
50
|
+
def repeated_permutation(num)
|
51
51
|
return to_enum(:repeated_permutation, num) unless block_given?
|
52
52
|
num = Backports.coerce_to_int(num)
|
53
53
|
if num <= 0
|
@@ -74,20 +74,22 @@ class Array
|
|
74
74
|
concat(slice!(0, n))
|
75
75
|
end unless method_defined? :rotate!
|
76
76
|
|
77
|
-
def select!
|
77
|
+
def select!
|
78
78
|
return to_enum(:select!) unless block_given?
|
79
79
|
reject!{|elem| ! yield elem}
|
80
80
|
end unless method_defined? :select!
|
81
81
|
|
82
|
-
def sort_by!
|
82
|
+
def sort_by!
|
83
83
|
return to_enum(:sort_by!) unless block_given?
|
84
|
-
|
84
|
+
raise "can't modify frozen array" if frozen?
|
85
|
+
replace sort_by{|e| yield e}
|
85
86
|
end unless method_defined? :sort_by!
|
86
87
|
|
87
88
|
unless [1,2].uniq!{}
|
88
|
-
def uniq_with_block!
|
89
|
+
def uniq_with_block!
|
89
90
|
return uniq_without_block! unless block_given?
|
90
|
-
|
91
|
+
replace self if frozen? # force error
|
92
|
+
u = uniq{|e| yield e}
|
91
93
|
replace u unless u.size == size
|
92
94
|
end
|
93
95
|
Backports.alias_method_chain self, :uniq!, :block
|
data/lib/backports/tools.rb
CHANGED
@@ -23,7 +23,7 @@ module Backports
|
|
23
23
|
|
24
24
|
# Metaprogramming utility to make block optional.
|
25
25
|
# Tests first if block is already optional when given options
|
26
|
-
def self.make_block_optional
|
26
|
+
def self.make_block_optional(mod, *methods)
|
27
27
|
options = methods.last.is_a?(Hash) ? methods.pop : {}
|
28
28
|
methods.each do |selector|
|
29
29
|
unless mod.method_defined? selector
|
@@ -55,7 +55,7 @@ module Backports
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Metaprogramming utility to convert the first file argument to path
|
58
|
-
def self.convert_first_argument_to_path
|
58
|
+
def self.convert_first_argument_to_path(mod, *methods)
|
59
59
|
methods.each do |selector|
|
60
60
|
unless mod.method_defined? selector
|
61
61
|
warn "#{mod}##{selector} is not defined, so argument can't converted to path"
|
@@ -81,7 +81,7 @@ module Backports
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# Metaprogramming utility to convert all file arguments to paths
|
84
|
-
def self.convert_all_arguments_to_path
|
84
|
+
def self.convert_all_arguments_to_path(mod, skip, *methods)
|
85
85
|
methods.each do |selector|
|
86
86
|
unless mod.method_defined? selector
|
87
87
|
warn "#{mod}##{selector} is not defined, so arguments can't converted to path"
|
@@ -100,7 +100,12 @@ module Backports
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def self.convert_to_path(file_or_path)
|
103
|
-
|
103
|
+
begin
|
104
|
+
file_or_path = file_or_path.to_path
|
105
|
+
rescue NoMethodError
|
106
|
+
# ignore
|
107
|
+
end
|
108
|
+
coerce_to(file_or_path, String, :to_str)
|
104
109
|
end
|
105
110
|
|
106
111
|
# Modified to avoid polluting Module if so desired
|
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: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
|
-
- 1
|
7
|
-
- 18
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.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:
|
18
|
+
date: 2011-03-04 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -92,7 +93,6 @@ files:
|
|
92
93
|
- lib/backports/1.9.2/hash.rb
|
93
94
|
- lib/backports/1.9.2/kernel.rb
|
94
95
|
- lib/backports/1.9.2/match_data.rb
|
95
|
-
- lib/backports/1.9.2/method.rb
|
96
96
|
- lib/backports/1.9.2/random.rb
|
97
97
|
- lib/backports/1.9.2/random/MT19937.rb
|
98
98
|
- lib/backports/1.9.2/random/bits_and_bytes.rb
|
@@ -141,23 +141,27 @@ rdoc_options:
|
|
141
141
|
require_paths:
|
142
142
|
- lib
|
143
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
144
145
|
requirements:
|
145
146
|
- - ">="
|
146
147
|
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
147
149
|
segments:
|
148
150
|
- 0
|
149
151
|
version: "0"
|
150
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
151
154
|
requirements:
|
152
155
|
- - ">="
|
153
156
|
- !ruby/object:Gem::Version
|
157
|
+
hash: 3
|
154
158
|
segments:
|
155
159
|
- 0
|
156
160
|
version: "0"
|
157
161
|
requirements: []
|
158
162
|
|
159
163
|
rubyforge_project: backports
|
160
|
-
rubygems_version: 1.3.
|
164
|
+
rubygems_version: 1.3.7
|
161
165
|
signing_key:
|
162
166
|
specification_version: 3
|
163
167
|
summary: Backports of Ruby 1.8.7+ for older ruby.
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# Standard in Ruby 1.9.2.
|
2
|
-
unless Kernel.method_defined? :respond_to_missing?
|
3
|
-
module MissingMethod
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
def call(*arg, &block)
|
7
|
-
receiver.send :method_missing, @name, *arg, &block
|
8
|
-
end
|
9
|
-
alias_method :[], :call
|
10
|
-
|
11
|
-
def eql?(method)
|
12
|
-
method.is_a?(MissingMethod) &&
|
13
|
-
receiver == method.receiver &&
|
14
|
-
name == method.name
|
15
|
-
end
|
16
|
-
alias_method :==, :eql?
|
17
|
-
|
18
|
-
def arity
|
19
|
-
-1
|
20
|
-
end
|
21
|
-
|
22
|
-
def owner
|
23
|
-
@receiver.class
|
24
|
-
end
|
25
|
-
|
26
|
-
def source_location
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_proc
|
31
|
-
get_block {|*arg| @receiver.send :method_missing, *arg}
|
32
|
-
end
|
33
|
-
|
34
|
-
def unbind
|
35
|
-
MissingUnboundMethod.new(owner, name)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.new(receiver, name)
|
39
|
-
m = receiver.method :respond_to_missing?
|
40
|
-
m.extend self
|
41
|
-
m.instance_variable_set :@name, name
|
42
|
-
m
|
43
|
-
end
|
44
|
-
#private
|
45
|
-
def get_block(&block)
|
46
|
-
block
|
47
|
-
end
|
48
|
-
private :get_block
|
49
|
-
end
|
50
|
-
|
51
|
-
module MissingUnboundMethod
|
52
|
-
attr_reader :name
|
53
|
-
attr_reader :owner
|
54
|
-
|
55
|
-
def self.new(owner, name)
|
56
|
-
um = owner.instance_method :respond_to_missing?
|
57
|
-
um.extend self
|
58
|
-
um.instance_variable_set :@name, name
|
59
|
-
um.instance_variable_set :@owner, owner
|
60
|
-
um
|
61
|
-
end
|
62
|
-
|
63
|
-
def arity
|
64
|
-
-1
|
65
|
-
end
|
66
|
-
|
67
|
-
def source_location
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
|
71
|
-
def bind(to)
|
72
|
-
raise TypeError, "bind argument must be an instance of #{@owner}" unless to.is_a? @owner
|
73
|
-
MissingMethod.new(to, @name)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
module Kernel
|
78
|
-
def respond_to_missing? method
|
79
|
-
false
|
80
|
-
end
|
81
|
-
|
82
|
-
def respond_to_with_call_to_respond_to_missing? method, include_priv=false
|
83
|
-
respond_to_without_call_to_respond_to_missing?(method, include_priv) || respond_to_missing?(method)
|
84
|
-
end
|
85
|
-
Backports.alias_method_chain self, :respond_to?, :call_to_respond_to_missing
|
86
|
-
|
87
|
-
def method_with_new_repond_to_missing(method)
|
88
|
-
method_without_new_repond_to_missing(method)
|
89
|
-
rescue NameError
|
90
|
-
respond_to_missing?(method) ? MissingMethod.new(self, method): raise
|
91
|
-
end
|
92
|
-
Backports.alias_method_chain self, :method, :new_repond_to_missing
|
93
|
-
|
94
|
-
def public_method_with_new_repond_to_missing(method)
|
95
|
-
public_method_without_new_repond_to_missing(method)
|
96
|
-
rescue NameError
|
97
|
-
respond_to_missing?(method) ? MissingMethod.new(self, method): raise
|
98
|
-
end
|
99
|
-
Backports.alias_method_chain self, :public_method, :new_repond_to_missing if method_defined? :public_method
|
100
|
-
end
|
101
|
-
end
|