Module: Einhorn::AbstractState

Included in:
State, TransientState
Defined in:
lib/einhorn.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/einhorn.rb', line 17

def method_missing(name, *args)
  if (name.to_s =~ /(.*)=$/) && state.has_key?($1.to_sym)
    state.send(:[]=, $1.to_sym, *args)
  elsif state.has_key?(name)
    state[name]
  else
    ds = default_state
    if ds.has_key?(name)
      ds[name]
    else
      super
    end
  end
end

Instance Method Details

#default_stateObject

Raises:

  • (NotImplementedError)


12
# File 'lib/einhorn.rb', line 12

def default_state; raise NotImplementedError.new('Override in extended modules'); end

#dumpable_stateObject



15
# File 'lib/einhorn.rb', line 15

def dumpable_state; state; end

#stateObject



13
# File 'lib/einhorn.rb', line 13

def state; @state ||= default_state; end

#state=(v) ⇒ Object



14
# File 'lib/einhorn.rb', line 14

def state=(v); @state = v; end