Class: Switch

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/whatnot/switch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Switch

Returns a new instance of Switch.



33
34
35
36
# File 'lib/whatnot/switch.rb', line 33

def initialize(payload)
  @payload = payload
  Switch.add(self)
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



38
39
40
# File 'lib/whatnot/switch.rb', line 38

def number
  @number
end

#payloadObject

Returns the value of attribute payload.



38
39
40
# File 'lib/whatnot/switch.rb', line 38

def payload
  @payload
end

Class Method Details

.add(switch) ⇒ Object



18
19
20
21
22
23
# File 'lib/whatnot/switch.rb', line 18

def self.add(switch)
  switch.number = next_number
  all[switch.number] = switch
  inc_next_number!
  switch
end

.allObject



10
11
12
# File 'lib/whatnot/switch.rb', line 10

def self.all
  @@all ||= {}
end

.eachObject



25
26
27
28
29
# File 'lib/whatnot/switch.rb', line 25

def self.each
  all.values.each do |switch|
    yield switch
  end
end

.find(number) ⇒ Object



14
15
16
# File 'lib/whatnot/switch.rb', line 14

def self.find(number)
  all[number]
end

.inc_next_number!Object



6
7
8
# File 'lib/whatnot/switch.rb', line 6

def self.inc_next_number!
  @@next_number = @@next_number ? @@next_number + 1 : 1
end

.next_numberObject



2
3
4
# File 'lib/whatnot/switch.rb', line 2

def self.next_number
  @@next_number ||= 1
end