marcandre-backports 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/README.rdoc +31 -36
  3. data/Rakefile +4 -27
  4. data/VERSION.yml +2 -2
  5. data/backports.gemspec +52 -32
  6. data/lib/backports/{argf.rb → 1.8.7/argf.rb} +8 -8
  7. data/lib/backports/{array.rb → 1.8.7/array.rb} +26 -43
  8. data/lib/backports/1.8.7/dir.rb +7 -0
  9. data/lib/backports/{enumerable.rb → 1.8.7/enumerable.rb} +22 -38
  10. data/lib/backports/1.8.7/enumerator.rb +19 -0
  11. data/lib/backports/1.8.7/env.rb +3 -0
  12. data/lib/backports/1.8.7/fixnum.rb +11 -0
  13. data/lib/backports/1.8.7/float.rb +4 -0
  14. data/lib/backports/1.8.7/hash.rb +23 -0
  15. data/lib/backports/1.8.7/integer.rb +23 -0
  16. data/lib/backports/{io.rb → 1.8.7/io.rb} +8 -7
  17. data/lib/backports/1.8.7/kernel.rb +39 -0
  18. data/lib/backports/{method.rb → 1.8.7/method.rb} +8 -8
  19. data/lib/backports/1.8.7/module.rb +7 -0
  20. data/lib/backports/1.8.7/numeric.rb +3 -0
  21. data/lib/backports/1.8.7/object_space.rb +5 -0
  22. data/lib/backports/1.8.7/range.rb +4 -0
  23. data/lib/backports/{regexp.rb → 1.8.7/regexp.rb} +2 -1
  24. data/lib/backports/1.8.7/string.rb +90 -0
  25. data/lib/backports/1.8.7/struct.rb +3 -0
  26. data/lib/backports/1.8.7/symbol.rb +6 -0
  27. data/lib/backports/1.8.7.rb +4 -0
  28. data/lib/backports/1.9/array.rb +12 -0
  29. data/lib/backports/1.9/enumerable.rb +8 -0
  30. data/lib/backports/1.9/enumerator.rb +15 -0
  31. data/lib/backports/1.9/hash.rb +15 -0
  32. data/lib/backports/1.9/integer.rb +3 -0
  33. data/lib/backports/1.9/kernel.rb +11 -0
  34. data/lib/backports/1.9/string.rb +39 -0
  35. data/lib/backports/{symbol.rb → 1.9/symbol.rb} +1 -6
  36. data/lib/backports/1.9.rb +5 -0
  37. data/lib/backports/rails/array.rb +6 -0
  38. data/lib/backports/rails/enumerable.rb +12 -0
  39. data/lib/backports/rails/hash.rb +31 -0
  40. data/lib/backports/rails/kernel.rb +12 -0
  41. data/lib/backports/rails/module.rb +6 -0
  42. data/lib/backports/rails/string.rb +42 -0
  43. data/lib/backports/rails.rb +4 -0
  44. data/lib/backports/tools.rb +117 -0
  45. data/lib/backports.rb +4 -15
  46. data/test/enumerator_test.rb +3 -3
  47. data/test/test_helper.rb +1 -3
  48. metadata +48 -32
  49. data/lib/backports/core_ext.rb +0 -61
  50. data/lib/backports/dir.rb +0 -7
  51. data/lib/backports/enumerator.rb +0 -43
  52. data/lib/backports/env.rb +0 -3
  53. data/lib/backports/fixnum.rb +0 -11
  54. data/lib/backports/float.rb +0 -4
  55. data/lib/backports/hash.rb +0 -64
  56. data/lib/backports/integer.rb +0 -25
  57. data/lib/backports/kernel.rb +0 -55
  58. data/lib/backports/module.rb +0 -30
  59. data/lib/backports/numeric.rb +0 -3
  60. data/lib/backports/object_space.rb +0 -5
  61. data/lib/backports/range.rb +0 -4
  62. data/lib/backports/string.rb +0 -167
  63. data/lib/backports/struct.rb +0 -3
  64. /data/lib/backports/{binding.rb → 1.8.7/binding.rb} +0 -0
  65. /data/lib/backports/{gc.rb → 1.8.7/gc.rb} +0 -0
  66. /data/lib/backports/{proc.rb → 1.8.7/proc.rb} +0 -0
  67. /data/lib/backports/{process.rb → 1.8.7/process.rb} +0 -0
@@ -1,167 +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
- alias_method :bytesize, :length unless method_defined? :bytesize
17
-
18
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
19
- def camelize(first_letter = :upper)
20
- if first_letter == :upper
21
- gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
22
- else
23
- first.downcase + camelize[1..-1]
24
- end
25
- end unless method_defined? :camelize
26
-
27
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
28
- def chr
29
- chars.first
30
- end unless method_defined? :chr
31
-
32
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
33
- def clear
34
- self[0,length] = ""
35
- self
36
- end unless method_defined? :clear?
37
-
38
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
39
- def codepoints
40
- return to_enum(:codepoints) unless block_given?
41
- each_char.each do |s|
42
- utf8 = s.each_byte.to_a
43
- utf8[0] &= 0xff >> utf8.size # clear high bits (1 to 4, depending of number of bytes used)
44
- yield utf8.inject{|result, b| (result << 6) + (b & 0x3f) }
45
- end
46
- end unless method_defined? :codepoints
47
-
48
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
49
- def constantize
50
- names = split('::')
51
- names.shift if names.empty? || names.first.empty?
52
-
53
- constant = Object
54
- names.each do |name|
55
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
56
- end
57
- constant
58
- end unless method_defined? :constantize
59
-
60
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
61
- def dasherize
62
- gsub(/_/, '-')
63
- end unless method_defined? :dasherize
64
-
65
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
66
- def demodulize
67
- gsub(/^.*::/, '')
68
- end unless method_defined? :demodulize
69
-
70
- make_block_optional :each_byte, :each, :each_line, :test_on => "abc"
71
-
72
- # gsub: Left alone because of $~, $1, etc... which needs to be "pushed" up one level
73
- # It's possible to do so, but it's a method that is used everywhere so i felt
74
- # the performance hit was too big compared to the dubious gain.
75
-
76
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
77
- unless method_defined? :each_char
78
- def each_char(&block)
79
- return to_enum(:each_char) unless block_given?
80
- scan(/./, &block)
81
- end
82
-
83
- alias_method :chars, :each_char unless method_defined? :chars
84
- end
85
-
86
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
87
- alias_method :each_codepoint, :codepoints unless method_defined? :each_codepoint
88
-
89
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
90
- def end_with?(*suffixes)
91
- suffixes.each do |suffix|
92
- next unless suffix.respond_to? :to_str
93
- suffix = suffix.to_str
94
- return true if self[-suffix.length, suffix.length] == suffix
95
- end
96
- false
97
- end unless method_defined? :end_with?
98
-
99
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
100
- def getbyte(i)
101
- self[i]
102
- end unless method_defined? :getbyte
103
-
104
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
105
- unless ("check partition".partition(" ") rescue false)
106
- def partition_with_new_meaning(pattern = Undefined, &block)
107
- return partition_without_new_meaning(&block) if pattern == Undefined
108
- pattern = Type.coerce_to(pattern, String, :to_str) unless pattern.is_a? Regexp
109
- i = index(pattern)
110
- return [self, "", ""] unless i
111
- if pattern.is_a? Regexp
112
- match = Regexp.last_match
113
- [match.pre_match, match[0], match.post_match]
114
- else
115
- last = i+pattern.length
116
- [self[0...i], self[i...last], self[last...length]]
117
- end
118
- end
119
- alias_method_chain :partition, :new_meaning
120
- end
121
-
122
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
123
- def rpartition(pattern)
124
- pattern = Type.coerce_to(pattern, String, :to_str) unless pattern.is_a? Regexp
125
- i = rindex(pattern)
126
- return ["", "", self] unless i
127
-
128
- if pattern.is_a? Regexp
129
- match = Regexp.last_match
130
- [match.pre_match, match[0], match.post_match]
131
- else
132
- last = i+pattern.length
133
- [self[0...i], self[i...last], self[last...length]]
134
- end
135
- end unless method_defined? :rpartition
136
-
137
-
138
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
139
- def start_with?(*prefixes)
140
- prefixes.each do |prefix|
141
- next unless prefix.respond_to? :to_str
142
- prefix = prefix.to_str
143
- return true if self[0, prefix.length] == prefix
144
- end
145
- false
146
- end unless method_defined? :start_with?
147
-
148
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
149
- def underscore
150
- gsub(/::/, '/').
151
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
152
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
153
- tr("-", "_").
154
- downcase
155
- end unless method_defined? :underscore
156
-
157
- unless ("abc".upto("def", true) rescue false)
158
- def upto_with_exclusive(to, excl=false, &block)
159
- return upto_without_exclusive(to, &block) if block_given? && !excl
160
- enum = Range.new(self, to, excl).to_enum
161
- return enum unless block_given?
162
- enum.each(&block)
163
- self
164
- end
165
- alias_method_chain :upto, :exclusive
166
- end
167
- end
@@ -1,3 +0,0 @@
1
- class Struct
2
- make_block_optional :each, :each_pair, :test_on => Struct.new(:foo, :bar)
3
- end
File without changes
File without changes
File without changes
File without changes