Skip to content

Commit

Permalink
Fix Range#min, Range#max for Time range on X19
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Nov 20, 2012
1 parent f0bd4cb commit 04c2c40
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions kernel/common/range19.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@ def first(n=undefined)
end

def max(&block)
raise TypeError, "cannot exclude non Integer end value" if @end.kind_of?(Float) && @excl
return super(&block) if block_given? || (@excl && !@end.kind_of?(Numeric))
return nil unless @end > @begin

return super(&block) if block_given?
return nil if @end < @begin || (@excl && @end == @begin)
return @end if @end.kind_of?(Float) || (!@end.kind_of?(Float) && !@excl)
super
if @excl
unless @end.kind_of?(Integer)
raise TypeError, "cannot exclude non Integer end value"
end

unless @begin.kind_of?(Integer)
raise TypeError, "cannot exclude end value with non Integer begin value"
end

return @end - 1
end

@end
end

def min(&block)
return super(&block) if block_given?
return nil if @end < @begin || (@excl && @end == @begin)
return @begin if @begin.kind_of?(Float)
super
@begin
end

protected
Expand Down

0 comments on commit 04c2c40

Please sign in to comment.