backports 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.rb +4 -15
  7. data/lib/backports/1.8.7.rb +4 -0
  8. data/lib/backports/{argf.rb → 1.8.7/argf.rb} +8 -8
  9. data/lib/backports/{array.rb → 1.8.7/array.rb} +26 -43
  10. data/lib/backports/{binding.rb → 1.8.7/binding.rb} +0 -0
  11. data/lib/backports/1.8.7/dir.rb +7 -0
  12. data/lib/backports/{enumerable.rb → 1.8.7/enumerable.rb} +22 -38
  13. data/lib/backports/1.8.7/enumerator.rb +19 -0
  14. data/lib/backports/1.8.7/env.rb +3 -0
  15. data/lib/backports/1.8.7/fixnum.rb +11 -0
  16. data/lib/backports/1.8.7/float.rb +4 -0
  17. data/lib/backports/{gc.rb → 1.8.7/gc.rb} +0 -0
  18. data/lib/backports/1.8.7/hash.rb +23 -0
  19. data/lib/backports/1.8.7/integer.rb +23 -0
  20. data/lib/backports/{io.rb → 1.8.7/io.rb} +8 -7
  21. data/lib/backports/1.8.7/kernel.rb +39 -0
  22. data/lib/backports/{method.rb → 1.8.7/method.rb} +8 -8
  23. data/lib/backports/1.8.7/module.rb +7 -0
  24. data/lib/backports/1.8.7/numeric.rb +3 -0
  25. data/lib/backports/1.8.7/object_space.rb +5 -0
  26. data/lib/backports/{proc.rb → 1.8.7/proc.rb} +0 -0
  27. data/lib/backports/{process.rb → 1.8.7/process.rb} +0 -0
  28. data/lib/backports/1.8.7/range.rb +4 -0
  29. data/lib/backports/{regexp.rb → 1.8.7/regexp.rb} +2 -1
  30. data/lib/backports/1.8.7/string.rb +90 -0
  31. data/lib/backports/1.8.7/struct.rb +3 -0
  32. data/lib/backports/1.8.7/symbol.rb +6 -0
  33. data/lib/backports/1.9.rb +5 -0
  34. data/lib/backports/1.9/array.rb +12 -0
  35. data/lib/backports/1.9/enumerable.rb +8 -0
  36. data/lib/backports/1.9/enumerator.rb +15 -0
  37. data/lib/backports/1.9/hash.rb +15 -0
  38. data/lib/backports/1.9/integer.rb +3 -0
  39. data/lib/backports/1.9/kernel.rb +11 -0
  40. data/lib/backports/1.9/string.rb +39 -0
  41. data/lib/backports/{symbol.rb → 1.9/symbol.rb} +1 -6
  42. data/lib/backports/rails.rb +4 -0
  43. data/lib/backports/rails/array.rb +6 -0
  44. data/lib/backports/rails/enumerable.rb +12 -0
  45. data/lib/backports/rails/hash.rb +31 -0
  46. data/lib/backports/rails/kernel.rb +12 -0
  47. data/lib/backports/rails/module.rb +6 -0
  48. data/lib/backports/rails/string.rb +42 -0
  49. data/lib/backports/tools.rb +117 -0
  50. data/test/enumerator_test.rb +3 -3
  51. data/test/test_helper.rb +1 -3
  52. metadata +50 -31
  53. data/lib/backports/core_ext.rb +0 -61
  54. data/lib/backports/dir.rb +0 -7
  55. data/lib/backports/enumerator.rb +0 -43
  56. data/lib/backports/env.rb +0 -3
  57. data/lib/backports/fixnum.rb +0 -11
  58. data/lib/backports/float.rb +0 -4
  59. data/lib/backports/hash.rb +0 -64
  60. data/lib/backports/integer.rb +0 -25
  61. data/lib/backports/kernel.rb +0 -55
  62. data/lib/backports/module.rb +0 -30
  63. data/lib/backports/numeric.rb +0 -3
  64. data/lib/backports/object_space.rb +0 -5
  65. data/lib/backports/range.rb +0 -4
  66. data/lib/backports/string.rb +0 -167
  67. data/lib/backports/struct.rb +0 -3
@@ -1,61 +0,0 @@
1
- # These are non-standard extensions
2
-
3
- class Module
4
- # Metaprogramming utility to make block optional.
5
- # Tests first if block is already optional when given options
6
- def make_block_optional(*methods)
7
- options = methods.extract_options!
8
- methods.each do |selector|
9
- next unless method_defined? selector
10
- unless options.empty?
11
- test_on = options[:test_on] || self.new
12
- next if (test_on.send(selector, *options.fetch(:arg, [])) rescue false)
13
- end
14
-
15
- arity = instance_method(selector).arity
16
- last_arg = []
17
- if arity < 0
18
- last_arg = ["*rest"]
19
- arity = -1-arity
20
- end
21
- arg_sequence = ((0...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")
22
-
23
- alias_method_chain(selector, :optional_block) do |aliased_target, punctuation|
24
- module_eval <<-end_eval
25
- def #{aliased_target}_with_optional_block#{punctuation}(#{arg_sequence})
26
- return to_enum(:#{aliased_target}_without_optional_block#{punctuation}, #{arg_sequence}) unless block_given?
27
- #{aliased_target}_without_optional_block#{punctuation}(#{arg_sequence})
28
- end
29
- end_eval
30
- end
31
- end
32
- end
33
- end
34
-
35
- module Type
36
- # From Rubinius
37
- class << self
38
- def coerce_to(obj, cls, meth)
39
- return obj if obj.kind_of?(cls)
40
-
41
- begin
42
- ret = obj.__send__(meth)
43
- rescue Exception => e
44
- raise TypeError, "Coercion error: #{obj.inspect}.#{meth} => #{cls} failed:\n" \
45
- "(#{e.message})"
46
- end
47
- raise TypeError, "Coercion error: obj.#{meth} did NOT return a #{cls} (was #{ret.class})" unless ret.kind_of? cls
48
- ret
49
- end unless method_defined? :coerce_to
50
- end
51
-
52
- def self.coerce_to_comparison(a, b, cmp = (a <=> b))
53
- raise ArgumentError, "comparison of #{a} with #{b} failed" if cmp.nil?
54
- return 1 if cmp > 0
55
- return -1 if cmp < 0
56
- 0
57
- end unless method_defined? :coerce_to_comparison
58
- end
59
-
60
- # From Rubinius
61
- Undefined = Object.new unless Kernel.const_defined? :Undefined
@@ -1,7 +0,0 @@
1
- class Dir
2
- make_block_optional :each, :test_on => Dir.new(".")
3
- class << self
4
- make_block_optional :foreach, :test_on => Dir, :arg => "."
5
- end
6
- end
7
-
@@ -1,43 +0,0 @@
1
- class Enumerator
2
- alias_method :with_object, :each_with_object unless method_defined? :with_object
3
-
4
- def next
5
- require 'generator'
6
- @generator ||= Generator.new(self)
7
- raise StopIteration unless @generator.next?
8
- @generator.next
9
- end unless method_defined? :next
10
-
11
- def rewind
12
- @object.rewind if @object.respond_to? :rewind
13
- require 'generator'
14
- @generator ||= Generator.new(self)
15
- @generator.rewind
16
- self
17
- end unless method_defined? :rewind
18
-
19
- # new with block, standard in Ruby 1.9
20
- unless (self.new{} rescue false)
21
- class Yielder
22
- def initialize(&block)
23
- @main_block = block
24
- end
25
-
26
- def each(&block)
27
- @final_block = block
28
- @main_block.call(self)
29
- end
30
-
31
- def yield(*arg)
32
- @final_block.yield(*arg)
33
- end
34
- end
35
-
36
- def initialize_with_optional_block(*arg, &block)
37
- @object = arg.first
38
- return initialize_without_optional_block(*arg, &nil) unless arg.empty? # Ruby 1.9 apparently ignores the block if any argument is present
39
- initialize_without_optional_block(Yielder.new(&block))
40
- end
41
- alias_method_chain :initialize, :optional_block
42
- end
43
- end
@@ -1,3 +0,0 @@
1
- class << ENV
2
- make_block_optional :delete_if, :each, :each_key, :each_pair, :each_value, :reject!, :select, :test_on => ENV
3
- end
@@ -1,11 +0,0 @@
1
- class Fixnum
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- def div(n)
4
- (self / n).to_i
5
- end unless method_defined? :div
6
-
7
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
8
- def fdiv(n)
9
- to_f / n
10
- end unless method_defined? :fdiv
11
- end
@@ -1,4 +0,0 @@
1
- class Fixnum
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- alias_method :fdiv, :/ unless method_defined? :fdiv
4
- end
@@ -1,64 +0,0 @@
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>
4
- class << self
5
- alias_method :original_constructor, :[]
6
- def [](*args)
7
- return original_constructor(*args) unless args.length == 1 && args.first.is_a?(Array)
8
- returning({}) do |h|
9
- args.first.each do |arr|
10
- next unless arr.respond_to? :to_ary
11
- arr = arr.to_ary
12
- next unless (1..2).include? arr.size
13
- h[arr.at(0)] = arr.at(1)
14
- end
15
- end
16
- end unless (Hash[[[:test, :test]]] rescue false)
17
-
18
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
19
- def try_convert(x)
20
- return nil unless x.respond_to? :to_hash
21
- x.to_hash
22
- end unless method_defined? :to_hash
23
- end
24
-
25
- make_block_optional :delete_if, :each, :each_key, :each_pair, :each_value, :reject, :reject!, :select, :test_on => {:hello => "world!"}
26
-
27
- # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
28
- def default_proc=(proc)
29
- replace(Hash.new(&Type.coerce_to(proc, Proc, :to_proc)).merge!(self))
30
- end unless method_defined? :default_proc=
31
-
32
- # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Hash.html]
33
- alias_method :key, :index unless method_defined? :key
34
-
35
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
36
- def reverse_merge(other_hash)
37
- other_hash.merge(self)
38
- end
39
-
40
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
41
- def reverse_merge!(other_hash)
42
- replace(reverse_merge(other_hash))
43
- end
44
-
45
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
46
- def symbolize_keys
47
- Hash[map{|key,value| [(key.to_sym rescue key) || key, value] }]
48
- end unless method_defined? :symbolize_keys
49
-
50
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
51
- def symbolize_keys!
52
- self.replace(self.symbolize_keys)
53
- end unless method_defined? :symbolize_keys!
54
-
55
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
56
- def stringify_keys
57
- Hash[map{|key,value| [key.to_s, value] }]
58
- end unless method_defined? :stringify_keys
59
-
60
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html]
61
- def stringify_keys!
62
- self.replace(self.stringify_keys)
63
- end unless method_defined? :stringify_keys!
64
- end
@@ -1,25 +0,0 @@
1
- class Integer
2
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
3
- def even?
4
- self[0].zero?
5
- end unless method_defined? :even?
6
-
7
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
8
- def odd?
9
- !even?
10
- end unless method_defined? :odd?
11
-
12
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
13
- def ord
14
- self
15
- end unless method_defined? :ord
16
-
17
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Fixnum.html]
18
- def pred
19
- self - 1
20
- end unless method_defined? :pred
21
-
22
- alias_method :magnitude, :abs unless method_defined? :magnitude
23
-
24
- make_block_optional :downto, :times, :upto, :test_on => 42, :arg => 42
25
- end
@@ -1,55 +0,0 @@
1
- require 'enumerator'
2
- # Must be defined outside of Kernel for jruby, see http://jira.codehaus.org/browse/JRUBY-3609
3
- Enumerator = Enumerable::Enumerator unless Kernel.const_defined? :Enumerator # Standard in ruby 1.9
4
-
5
- module Kernel
6
-
7
- def __callee__
8
- caller(1).first[/`(.*)'/,1].try(:to_sym)
9
- end unless (__callee__ || true rescue false)
10
-
11
- alias_method :__method__, :__callee__ unless (__method__ || true rescue false)
12
-
13
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
14
- def define_singleton_method(*args, &block)
15
- class << self
16
- self
17
- end.send(:define_method, *args, &block)
18
- end unless method_defined? :define_singleton_method
19
-
20
- # Standard in ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
21
- def instance_exec(*arg, &block)
22
- define_singleton_method(:"temporary method for instance_exec", &block)
23
- send(:"temporary method for instance_exec", *arg)
24
- end unless method_defined? :instance_exec
25
-
26
- # Loop. Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
27
- unless const_defined? :StopIteration
28
- class StopIteration < IndexError; end
29
-
30
- def loop_with_stop_iteration(&block)
31
- loop_without_stop_iteration(&block)
32
- rescue StopIteration
33
- # ignore silently
34
- end
35
- alias_method_chain :loop, :stop_iteration
36
- end
37
-
38
- # Standard in ruby 1.8.7. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
39
- def tap
40
- yield self
41
- self
42
- end unless method_defined? :tap
43
-
44
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/Object.html]
45
- def try(method_id, *args, &block)
46
- send(method_id, *args, &block) unless self.nil? #todo: check new def
47
- end unless method_defined? :try
48
-
49
- # Standard in rails. See official documentation[http://api.rubyonrails.org/classes/Object.html]
50
- def returning(obj)
51
- yield obj
52
- obj
53
- end unless method_defined? :returning
54
-
55
- end
@@ -1,30 +0,0 @@
1
- class Module
2
- # Standard in rails... See official documentation[http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Module.html]
3
- def alias_method_chain(target, feature)
4
- # Strip out punctuation on predicates or bang methods since
5
- # e.g. target?_without_feature is not a valid method name.
6
- aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
7
- yield(aliased_target, punctuation) if block_given?
8
-
9
- with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
10
-
11
- alias_method without_method, target
12
- alias_method target, with_method
13
-
14
- case
15
- when public_method_defined?(without_method)
16
- public target
17
- when protected_method_defined?(without_method)
18
- protected target
19
- when private_method_defined?(without_method)
20
- private target
21
- end
22
- end unless method_defined? :alias_method_chain
23
-
24
- # Can't use alias_method here because of jruby (see http://jira.codehaus.org/browse/JRUBY-2435 )
25
- def module_exec(*arg, &block)
26
- instance_exec(*arg, &block)
27
- end unless method_defined? :module_exec
28
- alias_method :class_exec, :module_exec unless method_defined? :class_exec
29
-
30
- end
@@ -1,3 +0,0 @@
1
- class Numeric
2
- make_block_optional :step, :test_on => 42, :arg => [100, 6]
3
- end
@@ -1,5 +0,0 @@
1
- module ObjectSpace
2
- module_eval do
3
- make_block_optional :each_object, :test_on => ObjectSpace
4
- end
5
- end
@@ -1,4 +0,0 @@
1
- class Range
2
- make_block_optional :each, :test_on => 69..666
3
- make_block_optional :step, :test_on => 69..666, :arg => 42
4
- end
@@ -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