Skip to content

Commit

Permalink
Fixed Range#last for 1.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Mar 23, 2013
1 parent 3e6c51b commit a5c159b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion kernel/common/range.rb
Expand Up @@ -70,7 +70,6 @@ def inspect
end

attr_reader :end
alias_method :last, :end

def step(step_size=1) # :yields: object
return to_enum(:step, step_size) unless block_given?
Expand Down
1 change: 1 addition & 0 deletions kernel/common/range18.rb
Expand Up @@ -40,6 +40,7 @@ def each(&block)
end

alias_method :first, :begin
alias_method :last, :end

protected

Expand Down
4 changes: 4 additions & 0 deletions kernel/common/range19.rb
Expand Up @@ -51,6 +51,10 @@ def first(n=undefined)
n.equal?(undefined) ? @begin : super
end

def last(n=undefined)
n.equal?(undefined) ? @end : to_a.last(n)
end

def max(&block)
return super(&block) if block_given? || (@excl && !@end.kind_of?(Numeric))
return nil if @end < @begin || (@excl && @end == @begin)
Expand Down

0 comments on commit a5c159b

Please sign in to comment.