Module: SlotMachine::Slot
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #end=(value) ⇒ Object
- #initialize(range_or_length) ⇒ Object
- #inspect ⇒ Object
- #length=(value) ⇒ Object
- #length? ⇒ Boolean
- #match(other, interval = nil) ⇒ Object
- #range? ⇒ Boolean
- #start=(value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/slot_machine/slot.rb', line 4 def self.included(base) base.class_eval do attr_reader :start, :end, :length def self.interval(value) @interval = value end def self.default_interval @interval || 10 end end end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 |
# File 'lib/slot_machine/slot.rb', line 58 def ==(other) self.class == other.class && self.start == other.start && self.end == other.end && self.length == other.length end |
#end=(value) ⇒ Object
41 42 43 |
# File 'lib/slot_machine/slot.rb', line 41 def end=(value) @end = end!(value) if range? end |
#initialize(range_or_length) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/slot_machine/slot.rb', line 18 def initialize(range_or_length) if range_or_length.is_a? Range @type = :range self.start = range_or_length.first self.end = range_or_length.last else @type = :length self.length = range_or_length end end |
#inspect ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/slot_machine/slot.rb', line 62 def inspect inspect_variables = begin if range? "@start=#{@start} @end=#{@end}" else "@length=#{@length}" end end "#<#{self.class.name} #{inspect_variables}>" end |
#length=(value) ⇒ Object
45 46 47 |
# File 'lib/slot_machine/slot.rb', line 45 def length=(value) @length = length!(value) if length? end |
#length? ⇒ Boolean
33 34 35 |
# File 'lib/slot_machine/slot.rb', line 33 def length? @type == :length end |
#match(other, interval = nil) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/slot_machine/slot.rb', line 49 def match(other, interval = nil) interval ||= self.class.default_interval raise ArgumentError, "Interval has to be greater than 0 (#{interval} given)" unless interval > 0 unless self.class == other.class other = self.class.new other end match_compared to_compared, other.to_compared, interval end |
#range? ⇒ Boolean
29 30 31 |
# File 'lib/slot_machine/slot.rb', line 29 def range? @type == :range end |
#start=(value) ⇒ Object
37 38 39 |
# File 'lib/slot_machine/slot.rb', line 37 def start=(value) @start = start!(value) if range? end |