backports 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/CHANGELOG.rdoc +10 -0
  2. data/README.rdoc +51 -44
  3. data/Rakefile +2 -6
  4. data/VERSION.yml +2 -3
  5. data/backports.gemspec +26 -15
  6. data/lib/backports.rb +1 -2
  7. data/lib/backports/1.8.7.rb +3 -3
  8. data/lib/backports/1.8.7/array.rb +1 -0
  9. data/lib/backports/1.8.7/kernel.rb +1 -1
  10. data/lib/backports/1.8.8.rb +5 -0
  11. data/lib/backports/1.8.8/array.rb +9 -0
  12. data/lib/backports/1.8.8/enumerable.rb +8 -0
  13. data/lib/backports/{1.9 → 1.8.8}/enumerator.rb +1 -1
  14. data/lib/backports/1.8.8/env.rb +3 -0
  15. data/lib/backports/{1.9 → 1.8.8}/hash.rb +2 -3
  16. data/lib/backports/1.8.8/io.rb +11 -0
  17. data/lib/backports/1.8.8/proc.rb +3 -0
  18. data/lib/backports/1.8.8/range.rb +3 -0
  19. data/lib/backports/1.8.8/regexp.rb +9 -0
  20. data/lib/backports/1.8.8/string.rb +33 -0
  21. data/lib/backports/1.8.rb +4 -0
  22. data/lib/backports/1.9.1.rb +5 -0
  23. data/lib/backports/{1.9 → 1.9.1}/dir.rb +0 -0
  24. data/lib/backports/{1.9 → 1.9.1}/file.rb +0 -0
  25. data/lib/backports/{1.9 → 1.9.1}/integer.rb +0 -0
  26. data/lib/backports/{1.9 → 1.9.1}/io.rb +0 -0
  27. data/lib/backports/{1.9 → 1.9.1}/kernel.rb +3 -3
  28. data/lib/backports/1.9.1/string.rb +20 -0
  29. data/lib/backports/{1.9 → 1.9.1}/symbol.rb +1 -1
  30. data/lib/backports/1.9.2.rb +5 -0
  31. data/lib/backports/{1.9 → 1.9.2}/enumerable.rb +0 -7
  32. data/lib/backports/{1.9 → 1.9.2}/method.rb +1 -1
  33. data/lib/backports/1.9.rb +3 -4
  34. data/lib/backports/basic_object.rb +1 -1
  35. data/lib/backports/rails.rb +1 -1
  36. data/lib/backports/tools.rb +12 -1
  37. metadata +26 -15
  38. data/lib/backports/1.9/array.rb +0 -12
  39. data/lib/backports/1.9/string.rb +0 -39
@@ -1,5 +1,15 @@
1
1
  = Packable --- History
2
2
 
3
+ == Version 1.12.0 - December 4th, 2009
4
+
5
+ * Finer grain includes (see README)
6
+ require "backports/1.9" # requires all ruby backports
7
+ require "backports/1.9.1" # requires all ruby backports up to 1.9.1 (but not 1.9.2)
8
+
9
+ * Backported all builtin methods of 1.8.8 (most of which where moved from the 1.9 backports)
10
+
11
+ * Refreshed README
12
+
3
13
  == Version 1.11.0 - November 4th, 2009
4
14
 
5
15
  * Added Enumerable#flat_map / collect_concat (Ruby 1.9)
@@ -1,84 +1,76 @@
1
1
  = Backports Library
2
2
 
3
- Would you like to use features of Ruby 1.8.7 without the need of having 1.8.7 installed? Simply
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!
4
4
 
5
- require 'backports/1.8.7'
5
+ 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
6
 
7
- All 1.8.7 features are now available! Many of the features of 1.9 are also available with
8
-
9
- require 'backports/1.9'
10
-
11
- Finally, some features of rails' active-support are also available with
12
-
13
- require 'backports/rails'
7
+ require 'backports'
14
8
 
15
- If you want them all:
9
+ Actually, it's tomorrow's standard, since this will bring Ruby 1.8.6 or 1.8.7 up to date with the upcoming Ruby 1.8.8, as well as include many features of Ruby 1.9.1 and the upcoming Ruby 1.9.2!
16
10
 
17
- require 'backports'
11
+ +Note+: Although I am a Ruby committer, this gem is a personal project and is not endorsed by ruby-core.
18
12
 
19
13
  == What's inside
20
14
 
21
- All features of 1.8.7 are backported (well, almost all, see the exception list bellow).
22
-
23
- Conditions for inclusion of ruby 1.9 and activesupport features:
15
+ Features in this gem:
24
16
  1. Won't break older code
25
- 2. Simple and self-contained
17
+ 2. Pure Ruby (no C extensions)
18
+ 3. Pass RubySpec[http://github.com/rubyspec/rubyspec]
19
+
20
+ Let's be a bit more precise about the breaking code business. It is of course entirely possible that code will break, for example some core methods are monkeypatched or if the code relies on a certain call raising an exception. Example: <tt>[42].sample rescue "dum example"</tt> will return <tt>"dum example"</tt> without this gem and <tt>42</tt> with it.
26
21
 
27
- For example, <tt>Module::instance_methods</tt> returns strings in 1.8 and symbols in 1.9; no change can be made without the risk of breaking existing code. Such incompatibilities between 1.8 and 1.9 methods are left unchanged.
22
+ A real incompatibility is, for example, <tt>Module::instance_methods</tt> which returns strings in 1.8 and symbols in 1.9. No change can be made without the risk of breaking existing code. Such incompatibilities are left unchanged.
28
23
 
29
- More complex features of active-support (even things like <tt>String::pluralize</tt>), won't be included. <tt>require 'activesupport'</tt> if you need them and are not in rails!
24
+ All features of 1.8.7 & 1.8.8 are backported (well, almost all, see the exception list bellow), and many of 1.9 are also.
25
+
26
+ Some generic and self-contained features of active-support are also included. By simple I mean that String#camelcase is there, but #pluralize isn't.
30
27
 
31
28
  == Installation & compatibility
32
29
 
33
- +backports+ is mirrored on Rubyforge and can thus be installed with:
30
+ +backports+ is can be installed with:
34
31
 
35
- sudo gem install backports
32
+ (sudo) gem install backports
36
33
 
37
34
  To use:
38
35
 
39
36
  require 'rubygems'
40
- require 'backports' # or a subset like "backports/1.8.7"
41
- # and off you go!
37
+ require 'backports' # or a subset, see next section
42
38
 
43
- Compatible with Ruby 1.8 & 1.9, jruby and rubinius.
39
+ Compatible with Ruby 1.8.6, 1.8.7, 1.9.1, JRuby and Rubinius, as well as the upcoming Ruby 1.8.8 and 1.9.2
44
40
 
45
41
  = Complete List of backports
46
42
 
47
43
  == Ruby 1.8.7
48
44
 
49
- Complete Ruby 1.8.7 backporting (core language). Refer to the official list of changes[http://svn.ruby-lang.org/repos/ruby/tags/v1_8_7/NEWS].
45
+ Complete Ruby 1.8.7 backporting (core language). Refer to the official list of changes[http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7/NEWS].
50
46
 
51
47
  Only exceptions:
52
- * String#gsub
53
- * GC.stress=
54
- * Array#choice (use Array#sample instead)
55
- * recursive data handling (Array, Hash, ...)
48
+ * String#gsub (the form returning an enumerator)
49
+ * GC.stress= (not implemented)
50
+ * Array#choice (removed in 1.8.8, use Array#sample instead)
56
51
 
57
- Libraries have not been backported. See at the end for list of known library backports
52
+ To include _only_ these backports, <tt>require "backports/1.8.7"</tt>
58
53
 
59
- == Ruby 1.9
54
+ == Ruby 1.8.8
60
55
 
61
- Additionally, the following Ruby 1.9 have been backported:
56
+ Complete Ruby 1.8.8 backporting (core language). In case you are wondering: no, it's not out yet :-). Refer to the official list of changes[http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/NEWS].
62
57
 
63
- * Array
64
- * +try_convert+
58
+ Only exception:
59
+ * Enumerator#rewind (incompatible change, so won't be implemented)
65
60
 
66
- * Enumerable
67
- * +each_with_object+
68
- * +chunk+
61
+ To include _only_ these backports and those preceeding, <tt>require "backports/1.8.8"</tt>.
69
62
 
70
- * Enumerator
71
- * +new+ (with block)
72
- * +flat_map+, +collect_concat+
63
+ == Ruby 1.9.1
64
+
65
+ Additionally, the following Ruby 1.9 features have been backported:
73
66
 
74
67
  * File
75
68
  * +binread+
76
69
  * +to_path+
77
70
  * All class methods accepting filenames will accept files or anything with a #to_path method.
78
71
 
79
- * Hash
80
- * +try_convert+
81
- * <tt>default_proc=</tt>
72
+ * IO
73
+ * +bin_read+
82
74
 
83
75
  * Kernel
84
76
  * +require_relative+
@@ -87,13 +79,11 @@ Additionally, the following Ruby 1.9 have been backported:
87
79
  * +define_singleton_method+
88
80
  * +public_method+
89
81
  * +public_send+
90
- * <tt>respond_to_missing?</tt>
91
82
 
92
83
  * Proc
93
84
  * +yield+
94
85
 
95
86
  * String
96
- * +try_convert+
97
87
  * <tt>ascii_only?</tt>
98
88
  * +chr+
99
89
  * +clear+
@@ -101,11 +91,26 @@ Additionally, the following Ruby 1.9 have been backported:
101
91
 
102
92
  +Enumerator+ can be accessed directly (instead of <tt>Enumerable::Enumerator</tt>)
103
93
 
94
+ To include _only_ these backports and those of the 1.8 line, <tt>require "backports/1.9.1"</tt>.
95
+
104
96
  Moreover, a pretty good imitation of BasicObject is available,
105
97
  but since it is only an imitation, it must be required explicitly:
106
98
 
107
99
  require 'backports/basic_object'
108
100
 
101
+ == Ruby 1.9.2
102
+
103
+ Finally, some Ruby 1.9.2 features have been backported. As this version has not been feature frozen yet, changes are still possible.
104
+
105
+ * Enumerable
106
+ * +flat_map+, +collect_concat+
107
+ * +chunk+
108
+
109
+ * Object
110
+ * <tt>respond_to_missing?</tt>
111
+
112
+ To include all Ruby backports but not those of Rails, <tt>require "backports/1.9.2"</tt>.
113
+
109
114
  == Rails
110
115
 
111
116
  Some generic methods from Rails methods have been copied:
@@ -129,9 +134,11 @@ Some generic methods from Rails methods have been copied:
129
134
  * +dasherize+, +demodulize+
130
135
  * +constantize+
131
136
 
137
+ To include _only_ these Rails backports but not those of Ruby, <tt>require "backports/rails"</tt>.
138
+
132
139
  == Libraries
133
140
 
134
- Libraries have not been backported. I am aware of following the backport gems:
141
+ Libraries have not been backported. I am aware of the following backport gems:
135
142
 
136
143
  * Net::SMTP for Ruby 1.8.6: smtp_tls[http://seattlerb.rubyforge.org/smtp_tls/]
137
144
 
data/Rakefile CHANGED
@@ -6,12 +6,10 @@ begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
8
  gem.name = "backports"
9
- gem.summary = "Backports or ruby 1.8.7+ & rails for older ruby."
9
+ gem.summary = "Backports of Ruby 1.8.7+ for older ruby."
10
10
  gem.email = "github@marc-andre.ca"
11
11
  gem.homepage = "http://github.com/marcandre/backports"
12
12
  gem.authors = ["Marc-André Lafortune"]
13
- gem.rubyforge_project = "backports"
14
-
15
13
  gem.description = <<-EOS
16
14
  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.
17
15
  EOS
@@ -21,11 +19,9 @@ begin
21
19
  '--line-numbers' << '--inline-source'
22
20
 
23
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
+ gem.rubyforge_project = "backports"
24
23
  Jeweler::GemcutterTasks.new
25
24
  end
26
- Jeweler::RubyforgeTasks.new do |rubyforge|
27
- rubyforge.doc_task = "rdoc"
28
- end
29
25
  rescue LoadError
30
26
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
31
27
  end
@@ -1,5 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 11
4
- :patch: 2
5
- :build:
3
+ :minor: 12
4
+ :patch: 0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "1.11.2"
8
+ s.version = "1.12.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{2009-12-01}
12
+ s.date = %q{2009-12-05}
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}
@@ -53,19 +53,30 @@ Gem::Specification.new do |s|
53
53
  "lib/backports/1.8.7/string.rb",
54
54
  "lib/backports/1.8.7/struct.rb",
55
55
  "lib/backports/1.8.7/symbol.rb",
56
+ "lib/backports/1.8.8.rb",
57
+ "lib/backports/1.8.8/array.rb",
58
+ "lib/backports/1.8.8/enumerable.rb",
59
+ "lib/backports/1.8.8/enumerator.rb",
60
+ "lib/backports/1.8.8/env.rb",
61
+ "lib/backports/1.8.8/hash.rb",
62
+ "lib/backports/1.8.8/io.rb",
63
+ "lib/backports/1.8.8/proc.rb",
64
+ "lib/backports/1.8.8/range.rb",
65
+ "lib/backports/1.8.8/regexp.rb",
66
+ "lib/backports/1.8.8/string.rb",
67
+ "lib/backports/1.8.rb",
68
+ "lib/backports/1.9.1.rb",
69
+ "lib/backports/1.9.1/dir.rb",
70
+ "lib/backports/1.9.1/file.rb",
71
+ "lib/backports/1.9.1/integer.rb",
72
+ "lib/backports/1.9.1/io.rb",
73
+ "lib/backports/1.9.1/kernel.rb",
74
+ "lib/backports/1.9.1/string.rb",
75
+ "lib/backports/1.9.1/symbol.rb",
76
+ "lib/backports/1.9.2.rb",
77
+ "lib/backports/1.9.2/enumerable.rb",
78
+ "lib/backports/1.9.2/method.rb",
56
79
  "lib/backports/1.9.rb",
57
- "lib/backports/1.9/array.rb",
58
- "lib/backports/1.9/dir.rb",
59
- "lib/backports/1.9/enumerable.rb",
60
- "lib/backports/1.9/enumerator.rb",
61
- "lib/backports/1.9/file.rb",
62
- "lib/backports/1.9/hash.rb",
63
- "lib/backports/1.9/integer.rb",
64
- "lib/backports/1.9/io.rb",
65
- "lib/backports/1.9/kernel.rb",
66
- "lib/backports/1.9/method.rb",
67
- "lib/backports/1.9/string.rb",
68
- "lib/backports/1.9/symbol.rb",
69
80
  "lib/backports/basic_object.rb",
70
81
  "lib/backports/rails.rb",
71
82
  "lib/backports/rails/array.rb",
@@ -96,7 +107,7 @@ Gem::Specification.new do |s|
96
107
  s.require_paths = ["lib"]
97
108
  s.rubyforge_project = %q{backports}
98
109
  s.rubygems_version = %q{1.3.5}
99
- s.summary = %q{Backports or ruby 1.8.7+ & rails for older ruby.}
110
+ s.summary = %q{Backports of Ruby 1.8.7+ for older ruby.}
100
111
  s.test_files = [
101
112
  "test/array_test.rb",
102
113
  "test/basic_object_test.rb",
@@ -1,4 +1,3 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/backports/tools")
2
- Backports.require_relative "backports/1.8.7"
3
2
  Backports.require_relative "backports/1.9"
4
- Backports.require_relative "backports/rails"
3
+ Backports.require_relative "backports/rails"
@@ -1,4 +1,4 @@
1
+ # require this file to load all the backports of Ruby 1.8.7
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + "/tools")
2
- %w(module kernel array enumerable enumerator string symbol integer numeric fixnum hash proc binding dir io method range regexp struct float object_space argf gc env process).each do |lib|
3
- Backports.require_relative "1.8.7/#{lib}"
4
- end
4
+ Backports.require_relative_dir "1.8.7"
@@ -134,6 +134,7 @@ class Array
134
134
  end
135
135
 
136
136
  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
137
+ # Note: was named #choice in 1.8.7 and renamed in later versions
137
138
  def sample(n = Backports::Undefined)
138
139
  return self[rand(size)] if n == Backports::Undefined
139
140
  n = Backports.coerce_to(n, Fixnum, :to_int)
@@ -12,7 +12,7 @@ module Kernel
12
12
  end unless method_defined? :instance_exec
13
13
 
14
14
  # Loop. Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
15
- unless Object.const_defined? :StopIteration
15
+ unless const_defined? :StopIteration
16
16
  class StopIteration < IndexError; end
17
17
 
18
18
  def loop_with_stop_iteration(&block)
@@ -0,0 +1,5 @@
1
+ # require this file to load all the backports up to Ruby 1.8.8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/tools")
4
+ Backports.require_relative "1.8.7"
5
+ Backports.require_relative_dir "1.8.8"
@@ -0,0 +1,9 @@
1
+ class Array
2
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
3
+ class << self
4
+ def self.try_convert(obj)
5
+ return nil unless obj.respond_to?(:to_ary)
6
+ Backports.coerce_to(obj, Array, :to_ary)
7
+ end unless method_defined? :try_convert
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Enumerable
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, &block)
4
+ return to_enum(:each_with_object, memo) unless block_given?
5
+ each {|obj| block.call(obj, memo)}
6
+ memo
7
+ end unless method_defined? :each_with_object
8
+ end
@@ -1,5 +1,5 @@
1
1
  # Must be defined outside of Kernel for jruby, see http://jira.codehaus.org/browse/JRUBY-3609
2
- Enumerator = Enumerable::Enumerator unless Kernel.const_defined? :Enumerator # Standard in ruby 1.9
2
+ Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # Standard in ruby 1.9
3
3
 
4
4
  class Enumerator
5
5
  # new with block, standard in Ruby 1.9
@@ -0,0 +1,3 @@
1
+ class << ENV
2
+ alias_method :key, :index unless method_defined? :key
3
+ end
@@ -1,13 +1,12 @@
1
1
  class Hash
2
- # New Ruby 1.8.7+ constructor -- not documented, see redmine # 1385
3
- # <tt>Hash[[[:foo, :bar],[:hello, "world"]]] ==> {:foo => :bar, :hello => "world"}</tt>
2
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
4
3
  class << self
5
4
  def try_convert(x)
6
5
  return nil unless x.respond_to? :to_hash
7
6
  x.to_hash
8
7
  end unless method_defined? :try_convert
9
8
  end
10
-
9
+
11
10
  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
12
11
  def default_proc=(proc)
13
12
  replace(Hash.new(&Backports.coerce_to(proc, Proc, :to_proc)).merge!(self))
@@ -0,0 +1,11 @@
1
+ class IO
2
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/IO.html]
3
+ class << self
4
+ def self.try_convert(obj)
5
+ return nil unless obj.respond_to?(:to_io)
6
+ Backports.coerce_to(obj, IO, :to_io)
7
+ end unless method_defined? :try_convert
8
+ end
9
+
10
+ alias_method :ungetbyte, :ungetc unless method_defined? :ungetbyte
11
+ end
@@ -0,0 +1,3 @@
1
+ class Proc
2
+ alias_method :===, :call unless Proc.new{true} === 42
3
+ end
@@ -0,0 +1,3 @@
1
+ class Range
2
+ alias_method :cover?, :include? unless method_defined? :cover?
3
+ end
@@ -0,0 +1,9 @@
1
+ class Regexp
2
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
3
+ class << self
4
+ def self.try_convert(obj)
5
+ return nil unless obj.respond_to?(:to_regexp)
6
+ Backports.coerce_to(obj, Array, :to_regexp)
7
+ end unless method_defined? :try_convert
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ class String
2
+ class << self
3
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
4
+ def try_convert(x)
5
+ return nil unless x.respond_do(:to_str)
6
+ x.to_str
7
+ end unless method_defined? :try_convert
8
+ end
9
+
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
12
+
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
15
+
16
+ # Let's define this here, we can use it for ord:
17
+ unless method_defined? :codepoints
18
+ def codepoints
19
+ return to_enum(:codepoints) unless block_given?
20
+ each_char do |s|
21
+ utf8 = s.each_byte.to_a
22
+ utf8[0] &= 0xff >> utf8.size # clear high bits (1 to 4, depending of number of bytes used)
23
+ yield utf8.inject{|result, b| (result << 6) + (b & 0x3f) }
24
+ end
25
+ end
26
+ private :codepoints # Will be made available in 1.9.1/string.rb, if included
27
+ end
28
+
29
+ # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
30
+ def ord
31
+ codepoints.first
32
+ end unless method_defined? :ord
33
+ end
@@ -0,0 +1,4 @@
1
+ # require this file to load all the backports of the Ruby 1.8.x line
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/tools")
4
+ Backports.require_relative "1.8.8"
@@ -0,0 +1,5 @@
1
+ # require this file to load all the backports up to Ruby 1.9.1 (including all of 1.8.8 and below)
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/tools")
4
+ Backports.require_relative "1.8"
5
+ Backports.require_relative_dir "1.9.1"
File without changes
File without changes
File without changes
File without changes
@@ -11,9 +11,9 @@ module Kernel
11
11
  # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
12
12
  def require_relative(relative_feature)
13
13
  file = caller.first.split(/:\d/,2).first
14
- if /\A\((.*)\)/ =~ file # eval, etc.
15
- raise LoadError, "require_relative is called in #{$1}"
16
- end
14
+ if /\A\((.*)\)/ =~ file # eval, etc.
15
+ raise LoadError, "require_relative is called in #{$1}"
16
+ end
17
17
  require File.expand_path(relative_feature, File.dirname(file))
18
18
  end unless method_defined? :require_relative
19
19
  private :require_relative
@@ -0,0 +1,20 @@
1
+ class String
2
+
3
+ # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
4
+ def ascii_only?
5
+ !(self =~ /[^\x00-\x7f]/)
6
+ end unless method_defined? :ascii_only?
7
+
8
+ # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
9
+ def clear
10
+ self[0,length] = ""
11
+ self
12
+ end unless method_defined? :clear
13
+
14
+ # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
15
+ public :codepoints # Definition in 1.8.8/string.rb
16
+
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
19
+
20
+ end
@@ -28,5 +28,5 @@ class Symbol
28
28
  include Comparable
29
29
  alias_method :==, :dont_override_equal_please
30
30
  end
31
-
31
+
32
32
  end
@@ -0,0 +1,5 @@
1
+ # require this file to load all the backports up to Ruby 1.9.2
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/tools")
4
+ Backports.require_relative "1.9.1"
5
+ Backports.require_relative_dir "1.9.2"
@@ -1,11 +1,4 @@
1
1
  module Enumerable
2
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
3
- def each_with_object(memo, &block)
4
- return to_enum(:each_with_object, memo) unless block_given?
5
- each {|obj| block.call(obj, memo)}
6
- memo
7
- end unless method_defined? :each_with_object
8
-
9
2
  # Standard in Ruby 1.9.2 See official documentation[http://ruby-doc.org/core-1.9/classes/Enumerable.html]
10
3
  def chunk(initial_state = nil, &original_block)
11
4
  raise ArgumentError, "no block given" unless block_given?
@@ -1,4 +1,4 @@
1
- # Standard in Ruby 1.9.2. How do you call the backport of a future feature?
1
+ # Standard in Ruby 1.9.2.
2
2
  unless Kernel.method_defined? :respond_to_missing?
3
3
  module MissingMethod
4
4
  attr_reader :name
@@ -1,5 +1,4 @@
1
+ # require this file to load all the backports of Ruby
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + "/tools")
2
- Backports.require_relative "1.8.7"
3
- %w(array dir enumerable enumerator hash file integer io kernel method string symbol).each do |lib|
4
- Backports.require_relative "1.9/#{lib}"
5
- end
4
+ Backports.require_relative "1.9.2"
@@ -49,4 +49,4 @@ class BasicObject
49
49
  end
50
50
  end
51
51
  end
52
- end unless Kernel.const_defined? :BasicObject
52
+ end unless Kernel.const_defined? :BasicObject
@@ -1,4 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/tools")
2
2
  %w(array enumerable hash kernel module string).each do |lib|
3
3
  Backports.require_relative "rails/#{lib}"
4
- end
4
+ end
@@ -10,6 +10,17 @@ module Backports
10
10
  require File.expand_path(relative_feature, File.dirname(file))
11
11
  end
12
12
 
13
+ def self.require_relative_dir(relative_dir)
14
+ dir = File.expand_path(relative_dir, File.dirname(caller.first.split(/:\d/,2).first))
15
+ Dir.entries(dir).
16
+ map{|f| Regexp.last_match(1) if /^(.*)\.rb$/ =~ f}.
17
+ compact.
18
+ sort.
19
+ each do |f|
20
+ require File.expand_path(f, dir)
21
+ end
22
+ end
23
+
13
24
  # Metaprogramming utility to make block optional.
14
25
  # Tests first if block is already optional when given options
15
26
  def self.make_block_optional mod,*methods
@@ -163,4 +174,4 @@ module Backports
163
174
  @final_block.yield(*arg)
164
175
  end
165
176
  end
166
- end
177
+ end
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.11.2
4
+ version: 1.12.0
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: 2009-12-01 00:00:00 -05:00
12
+ date: 2009-12-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -58,19 +58,30 @@ files:
58
58
  - lib/backports/1.8.7/string.rb
59
59
  - lib/backports/1.8.7/struct.rb
60
60
  - lib/backports/1.8.7/symbol.rb
61
+ - lib/backports/1.8.8.rb
62
+ - lib/backports/1.8.8/array.rb
63
+ - lib/backports/1.8.8/enumerable.rb
64
+ - lib/backports/1.8.8/enumerator.rb
65
+ - lib/backports/1.8.8/env.rb
66
+ - lib/backports/1.8.8/hash.rb
67
+ - lib/backports/1.8.8/io.rb
68
+ - lib/backports/1.8.8/proc.rb
69
+ - lib/backports/1.8.8/range.rb
70
+ - lib/backports/1.8.8/regexp.rb
71
+ - lib/backports/1.8.8/string.rb
72
+ - lib/backports/1.8.rb
73
+ - lib/backports/1.9.1.rb
74
+ - lib/backports/1.9.1/dir.rb
75
+ - lib/backports/1.9.1/file.rb
76
+ - lib/backports/1.9.1/integer.rb
77
+ - lib/backports/1.9.1/io.rb
78
+ - lib/backports/1.9.1/kernel.rb
79
+ - lib/backports/1.9.1/string.rb
80
+ - lib/backports/1.9.1/symbol.rb
81
+ - lib/backports/1.9.2.rb
82
+ - lib/backports/1.9.2/enumerable.rb
83
+ - lib/backports/1.9.2/method.rb
61
84
  - lib/backports/1.9.rb
62
- - lib/backports/1.9/array.rb
63
- - lib/backports/1.9/dir.rb
64
- - lib/backports/1.9/enumerable.rb
65
- - lib/backports/1.9/enumerator.rb
66
- - lib/backports/1.9/file.rb
67
- - lib/backports/1.9/hash.rb
68
- - lib/backports/1.9/integer.rb
69
- - lib/backports/1.9/io.rb
70
- - lib/backports/1.9/kernel.rb
71
- - lib/backports/1.9/method.rb
72
- - lib/backports/1.9/string.rb
73
- - lib/backports/1.9/symbol.rb
74
85
  - lib/backports/basic_object.rb
75
86
  - lib/backports/rails.rb
76
87
  - lib/backports/rails/array.rb
@@ -128,7 +139,7 @@ rubyforge_project: backports
128
139
  rubygems_version: 1.3.5
129
140
  signing_key:
130
141
  specification_version: 3
131
- summary: Backports or ruby 1.8.7+ & rails for older ruby.
142
+ summary: Backports of Ruby 1.8.7+ for older ruby.
132
143
  test_files:
133
144
  - test/array_test.rb
134
145
  - test/basic_object_test.rb
@@ -1,12 +0,0 @@
1
- class Array
2
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Array.html]
3
- class << self
4
- # Try to convert obj into an array, using to_ary method.
5
- # Returns converted array or nil if obj cannot be converted
6
- # for any reason. This method is to check if an argument is an array.
7
- def try_convert(obj)
8
- return nil unless obj.respond_to?(:to_ary)
9
- Backports.coerce_to(obj, Array, :to_ary)
10
- end unless method_defined? :try_convert
11
- end
12
- end
@@ -1,39 +0,0 @@
1
- class String
2
- class << self
3
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
4
- def try_convert(x)
5
- return nil unless x.respond_do(:to_str)
6
- x.to_str
7
- end unless method_defined? :try_convert
8
- end
9
-
10
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
11
- def ascii_only?
12
- !(self =~ /[^\x00-\x7f]/)
13
- end unless method_defined? :ascii_only?
14
-
15
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
16
- def clear
17
- self[0,length] = ""
18
- self
19
- end unless method_defined? :clear
20
-
21
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
22
- def codepoints
23
- return to_enum(:codepoints) unless block_given?
24
- each_char do |s|
25
- utf8 = s.each_byte.to_a
26
- utf8[0] &= 0xff >> utf8.size # clear high bits (1 to 4, depending of number of bytes used)
27
- yield utf8.inject{|result, b| (result << 6) + (b & 0x3f) }
28
- end
29
- end unless method_defined? :codepoints
30
-
31
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
32
- alias_method :each_codepoint, :codepoints unless method_defined? :each_codepoint
33
-
34
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
35
- def getbyte(i)
36
- self[i]
37
- end unless method_defined? :getbyte
38
-
39
- end