Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Range#first on X19

Range#first has different behavior with Range#begin from Ruby 1.9.
It should return the first element, or the first n elements.

    range = 0..2

    range.begin    #=> 0
    range.begin(2) #=> ArgumentError

    range.first    #=> 0
    range.first(2) #=> [0, 1]
  • Loading branch information...
commit eaa08a2c083e4287c9e6ae7ebd95e580406875f8 1 parent 8676388
Kenichi Kamiya kachick authored
1  kernel/common/range.rb
View
@@ -106,7 +106,6 @@ def each(&block)
end
attr_reader :begin
- alias_method :first, :begin
def hash
excl = @excl ? 1 : 0
2  kernel/common/range18.rb
View
@@ -3,6 +3,8 @@
class Range
alias_method :===, :include?
+ alias_method :first, :begin
+
protected
def can_iterate_from?(object)
4 kernel/common/range19.rb
View
@@ -7,6 +7,10 @@ def ===(value)
alias_method :cover?, :include?
+ def first(n=undefined)
+ n.equal?(undefined) ? @begin : super
+ end
+
def max(&block)
raise TypeError, "cannot exclude non Integer end value" if @end.kind_of?(Float) && @excl
Please sign in to comment.
Something went wrong with that request. Please try again.