backports 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
  = Backports Library
2
2
 
3
- Can't remember if you can use Array#sample? 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? This gem is for you!
3
+ * Can't remember if you can use Array#sample?
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, (even the upcoming 1.9.2)?
6
+
7
+ This gem is for you!
4
8
 
5
9
  The goal of 'backports' is to make it easier to write ruby code that runs across different versions of Ruby. All you need to bring any version of Ruby up to today's standards:
6
10
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 13
4
- :patch: 1
4
+ :patch: 2
5
5
  :build:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "1.13.1"
8
+ s.version = "1.13.2"
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-01-22}
12
+ s.date = %q{2010-01-25}
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}
@@ -45,10 +45,10 @@ class << ARGF
45
45
  end unless method_defined? :each_char
46
46
 
47
47
  # No official documentation...
48
- alias_method :getbyte, :getc unless method_defined? :getbyte
48
+ Backports.alias_method self, :getbyte, :getc
49
49
 
50
50
  # No official documentation...
51
- alias_method :readbyte, :readchar unless method_defined? :readbyte
51
+ Backports.alias_method self, :readbyte, :readchar
52
52
 
53
53
  # No official documentation...
54
54
  def lines(*args)
@@ -186,7 +186,7 @@ module Enumerable
186
186
  found_one
187
187
  end unless method_defined? :one?
188
188
 
189
- alias_method :reduce, :inject unless method_defined? :reduce
189
+ Backports.alias_method self, :reduce, :inject
190
190
 
191
191
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
192
192
  def reverse_each(&block)
@@ -1,4 +1,4 @@
1
1
  class Fixnum
2
2
  # Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- alias_method :fdiv, :/ unless method_defined? :fdiv
3
+ Backports.alias_method self, :fdiv, :/
4
4
  end
@@ -39,5 +39,5 @@ class Hash
39
39
  Backports.make_block_optional self, :delete_if, :each, :each_key, :each_pair, :each_value, :reject, :reject!, :select, :test_on => {:hello => "world!"}
40
40
 
41
41
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
42
- alias_method :key, :index unless method_defined? :key
42
+ Backports.alias_method self, :key, :index
43
43
  end
@@ -44,8 +44,8 @@ class IO
44
44
  self
45
45
  end unless method_defined? :each_char
46
46
 
47
- alias_method :getbyte, :getc unless method_defined? :getbyte
48
- alias_method :readbyte, :readchar unless method_defined? :readchar
47
+ Backports.alias_method self, :getbyte, :getc
48
+ Backports.alias_method self, :readbyte, :readchar
49
49
 
50
50
  # Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/IO.html]
51
51
  def lines(*args)
@@ -3,5 +3,5 @@ class Module
3
3
  def module_exec(*arg, &block)
4
4
  instance_exec(*arg, &block)
5
5
  end unless method_defined? :module_exec
6
- alias_method :class_exec, :module_exec unless method_defined? :class_exec
6
+ Backports.alias_method self, :class_exec, :module_exec
7
7
  end
@@ -1,4 +1,4 @@
1
1
  class Proc
2
2
  # Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Proc.html]
3
- alias_method :yield, :call unless method_defined? :yield
3
+ Backports.alias_method self, :yield, :call
4
4
  end
@@ -1,6 +1,6 @@
1
1
  class String
2
2
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
3
- alias_method :bytesize, :length unless method_defined? :bytesize
3
+ Backports.alias_method self, :bytesize, :length
4
4
 
5
5
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
6
6
  def chr
@@ -10,7 +10,7 @@ class String
10
10
  Backports.make_block_optional self, :each_byte, :each_line, :test_on => "abc"
11
11
 
12
12
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
13
- alias_method :bytes, :each_byte unless method_defined? :bytes
13
+ Backports.alias_method self, :bytes, :each_byte
14
14
 
15
15
  Backports.make_block_optional self, :each, :test_on => "abc" if "is there still an each?".respond_to? :each
16
16
 
@@ -25,10 +25,10 @@ class String
25
25
  scan(/./, &block)
26
26
  end
27
27
 
28
- alias_method :chars, :each_char unless method_defined? :chars
28
+ Backports.alias_method self, :chars, :each_char
29
29
  end
30
30
 
31
- alias_method :lines, :each_line unless method_defined? :lines
31
+ Backports.alias_method self, :lines, :each_line
32
32
 
33
33
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
34
34
  def end_with?(*suffixes)
@@ -11,5 +11,5 @@ class Enumerator
11
11
  Backports.alias_method_chain self, :initialize, :optional_block
12
12
  end
13
13
 
14
- alias_method :with_object, :each_with_object unless method_defined? :with_object
14
+ Backports.alias_method self, :with_object, :each_with_object
15
15
  end
@@ -1,3 +1,3 @@
1
1
  class << ENV
2
- alias_method :key, :index unless method_defined? :key
2
+ Backports.alias_method self, :key, :index
3
3
  end
@@ -7,5 +7,5 @@ class IO
7
7
  end unless method_defined? :try_convert
8
8
  end
9
9
 
10
- alias_method :ungetbyte, :ungetc unless method_defined? :ungetbyte
10
+ Backports.alias_method self, :ungetbyte, :ungetc
11
11
  end
@@ -1,3 +1,3 @@
1
1
  class Range
2
- alias_method :cover?, :include? unless method_defined? :cover?
2
+ Backports.alias_method self, :cover?, :include?
3
3
  end
@@ -8,10 +8,10 @@ class String
8
8
  end
9
9
 
10
10
  # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
11
- alias_method :getbyte, :[] unless method_defined? :getbyte
11
+ Backports.alias_method self, :getbyte, :[]
12
12
 
13
13
  # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
14
- alias_method :setbyte, :[]= unless method_defined? :setbyte
14
+ Backports.alias_method self, :setbyte, :[]=
15
15
 
16
16
  # Let's define this here, we can use it for ord:
17
17
  unless method_defined? :codepoints
@@ -1,3 +1,3 @@
1
1
  class Dir
2
- alias_method :to_path, :path unless method_defined? :to_path
2
+ Backports.alias_method self, :to_path, :path
3
3
  end
@@ -3,7 +3,7 @@ class File
3
3
  stat.size
4
4
  end unless method_defined? :size
5
5
 
6
- alias_method :to_path, :path unless method_defined? :to_path
6
+ Backports.alias_method self, :to_path, :path
7
7
 
8
8
  class << self
9
9
  if RUBY_VERSION < '1.9' # can't see any other reasonable way to test than this
@@ -1,3 +1,3 @@
1
1
  class Integer
2
- alias_method :magnitude, :abs unless method_defined? :magnitude
2
+ Backports.alias_method self, :magnitude, :abs
3
3
  end
@@ -15,6 +15,6 @@ class String
15
15
  public :codepoints # Definition in 1.8.8/string.rb
16
16
 
17
17
  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
18
- alias_method :each_codepoint, :codepoints unless method_defined? :each_codepoint
18
+ Backports.alias_method self, :each_codepoint, :codepoints
19
19
 
20
20
  end
@@ -39,5 +39,5 @@ module Enumerable
39
39
  return to_enum(:flat_map) unless block_given?
40
40
  map(&block).flatten(1)
41
41
  end unless method_defined? :flat_map
42
- alias_method :collect_concat, :flat_map unless method_defined? :collect_concat
42
+ Backports.alias_method self, :collect_concat, :flat_map
43
43
  end
@@ -159,6 +159,14 @@ module Backports
159
159
  # (from Rubinius)
160
160
  Undefined = Object.new
161
161
 
162
+ # Used internally.
163
+ # Safe alias_method that will only alias if the source exists and destination doesn't
164
+ def self.alias_method(mod, new_name, old_name)
165
+ mod.class_eval do
166
+ alias_method new_name, old_name if method_defined?(old_name) and not method_defined?(new_name)
167
+ end
168
+ end
169
+
162
170
  # A simple class which allows the construction of Enumerator from a block
163
171
  class Yielder
164
172
  def initialize(&block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-22 00:00:00 -05:00
12
+ date: 2010-01-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15