Class: ThomasUtils::ConstantVar

Inherits:
Struct
  • Object
show all
Defined in:
lib/thomas_utils/constant_var.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#reasonObject

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



2
3
4
# File 'lib/thomas_utils/constant_var.rb', line 2

def reason
  @reason
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



2
3
4
# File 'lib/thomas_utils/constant_var.rb', line 2

def time
  @time
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/thomas_utils/constant_var.rb', line 2

def value
  @value
end

Class Method Details

.error(error) ⇒ Object



12
13
14
# File 'lib/thomas_utils/constant_var.rb', line 12

def self.error(error)
  new(Time.now, nil, error)
end

.noneObject



8
9
10
# File 'lib/thomas_utils/constant_var.rb', line 8

def self.none
  new(Time.now, nil, nil)
end

.value(value) ⇒ Object



4
5
6
# File 'lib/thomas_utils/constant_var.rb', line 4

def self.value(value)
  new(Time.now, value, nil)
end

Instance Method Details

#add_observer(observer = nil, func = :update, &block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/thomas_utils/constant_var.rb', line 21

def add_observer(observer = nil, func = :update, &block)
  if block
    observer = block
    func = :call
  end
  observer.public_send(func, time, value, reason)
end

#count_observersObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/thomas_utils/constant_var.rb', line 42

def count_observers
  raise NotImplementedError
end

#delete_observer(_) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/thomas_utils/constant_var.rb', line 34

def delete_observer(_)
  raise NotImplementedError
end

#delete_observersObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/thomas_utils/constant_var.rb', line 38

def delete_observers
  raise NotImplementedError
end

#value!Object



16
17
18
19
# File 'lib/thomas_utils/constant_var.rb', line 16

def value!
  raise reason if reason
  value
end

#with_observer(observer = nil, func = :update, &block) ⇒ Object



29
30
31
32
# File 'lib/thomas_utils/constant_var.rb', line 29

def with_observer(observer = nil, func = :update, &block)
  add_observer(observer, func, &block)
  self
end