Class: InfiniteTime
- Inherits:
-
Time
show all
- Defined in:
- lib/infinite_time.rb,
lib/infinite_time/version.rb,
lib/infinite_time/time_extension.rb,
lib/infinite_time/time_compatability.rb
Defined Under Namespace
Modules: TimeExtension
Classes: InvalidSign
Constant Summary
collapse
- VERSION =
'0.0.2'
Constants inherited
from Time
Time::Infinity
Instance Method Summary
collapse
#infinite?
Constructor Details
#initialize(sign = :+) ⇒ InfiniteTime
Returns a new instance of InfiniteTime.
17
18
19
20
21
|
# File 'lib/infinite_time.rb', line 17
def initialize sign = :+
sign = sign.to_sym
raise InvalidSign unless [:+, :-].include? sign
@sign = sign
end
|
Instance Method Details
#+(_) ⇒ Object
46
|
# File 'lib/infinite_time.rb', line 46
def + _; self; end
|
#-(_) ⇒ Object
47
|
# File 'lib/infinite_time.rb', line 47
def - _; self; end
|
#<=>(other) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/infinite_time.rb', line 31
def <=> other
case other
when InfiniteTime
if positive? && other.negative?
1
elsif negative? && other.positive?
-1
else
0
end
when Time then (positive?) ? 1 : -1
else raise ArgumentError, "comparison of InfiniteTime with #{other.inspect} failed"
end
end
|
#hash ⇒ Object
49
50
51
|
# File 'lib/infinite_time.rb', line 49
def hash
self.class.hash ^ @sign.hash
end
|
#negative? ⇒ Boolean
27
28
29
|
# File 'lib/infinite_time.rb', line 27
def negative?
!positive?
end
|
#positive? ⇒ Boolean
23
24
25
|
# File 'lib/infinite_time.rb', line 23
def positive?
@sign == :+
end
|
#strftime(_) ⇒ Object
67
|
# File 'lib/infinite_time.rb', line 67
def strftime _; to_s; end
|
#to_f ⇒ Object
53
54
55
|
# File 'lib/infinite_time.rb', line 53
def to_f
(positive?) ? Float::INFINITY : -Float::INFINITY
end
|
#to_i ⇒ Object
57
|
# File 'lib/infinite_time.rb', line 57
def to_i; raise TypeError, 'InfiniteTime has no Integer representation'; end
|
#to_r ⇒ Object
58
|
# File 'lib/infinite_time.rb', line 58
def to_r; raise TypeError, 'InfiniteTime has no Rational representation'; end
|
#to_s ⇒ Object
Also known as:
asctime, ctime, inspect
60
61
62
|
# File 'lib/infinite_time.rb', line 60
def to_s
"#{@sign}∞"
end
|