Module: IntervalNotation::BasicIntervals::ActslikeInterval
- Included in:
- ClosedClosedInterval, ClosedOpenInterval, OpenClosedInterval, OpenOpenInterval
- Defined in:
- lib/interval_notation/basic_intervals.rb
Class Method Summary collapse
Instance Method Summary collapse
- #closure ⇒ Object
- #eql?(other) ⇒ Boolean
- #finite? ⇒ Boolean
- #from_finite? ⇒ Boolean
- #from_to_s ⇒ Object
- #hash ⇒ Object
- #inspect ⇒ Object
- #length ⇒ Object
- #singular_point? ⇒ Boolean
- #to_finite? ⇒ Boolean
- #to_interval_set ⇒ Object
- #to_to_s ⇒ Object
Class Method Details
.included(base) ⇒ Object
14 15 16 17 18 |
# File 'lib/interval_notation/basic_intervals.rb', line 14 def self.included(base) base.class_eval do attr_reader :from, :to end end |
Instance Method Details
#closure ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/interval_notation/basic_intervals.rb', line 20 def closure if from_finite? if to_finite? ClosedClosedInterval.new(from, to) else ClosedOpenInterval.new(from, to) # to == +∞ end else if to_finite? OpenClosedInterval.new(from, to) # from == -∞ else OpenOpenInterval.new(from, to) # from == -∞, to == +∞ end end end |
#eql?(other) ⇒ Boolean
49 |
# File 'lib/interval_notation/basic_intervals.rb', line 49 def eql?(other); other.class.equal?(self.class) && from.eql?(other.from) && to.eql?(other.to); end |
#finite? ⇒ Boolean
40 |
# File 'lib/interval_notation/basic_intervals.rb', line 40 def finite?; from_finite? && to_finite?; end |
#from_finite? ⇒ Boolean
38 |
# File 'lib/interval_notation/basic_intervals.rb', line 38 def from_finite?; from.to_f.finite?; end |
#from_to_s ⇒ Object
42 |
# File 'lib/interval_notation/basic_intervals.rb', line 42 def from_to_s; from_finite? ? from : MINUS_INFINITY_SYMBOL; end |
#hash ⇒ Object
48 |
# File 'lib/interval_notation/basic_intervals.rb', line 48 def hash; [@from, @to, include_from?, include_to?].hash; end |
#inspect ⇒ Object
46 |
# File 'lib/interval_notation/basic_intervals.rb', line 46 def inspect; to_s; end |
#length ⇒ Object
45 |
# File 'lib/interval_notation/basic_intervals.rb', line 45 def length; to - from; end |
#singular_point? ⇒ Boolean
47 |
# File 'lib/interval_notation/basic_intervals.rb', line 47 def singular_point?; false; end |
#to_finite? ⇒ Boolean
39 |
# File 'lib/interval_notation/basic_intervals.rb', line 39 def to_finite?; to.to_f.finite?; end |
#to_interval_set ⇒ Object
36 |
# File 'lib/interval_notation/basic_intervals.rb', line 36 def to_interval_set; IntervalSet.new([self]); end |
#to_to_s ⇒ Object
43 |
# File 'lib/interval_notation/basic_intervals.rb', line 43 def to_to_s; to_finite? ? to : PLUS_INFINITY_SYMBOL; end |