Module: Einhorn::AbstractState
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/einhorn.rb', line 35
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_state ⇒ Object
13
14
15
|
# File 'lib/einhorn.rb', line 13
def default_state
raise NotImplementedError.new("Override in extended modules")
end
|
#dumpable_state ⇒ Object
25
26
27
|
# File 'lib/einhorn.rb', line 25
def dumpable_state
state
end
|
#respond_to_missing?(name) ⇒ Boolean
29
30
31
32
33
|
# File 'lib/einhorn.rb', line 29
def respond_to_missing?(name)
((name.to_s =~ /(.*)=$/) && state.has_key?($1.to_sym)) ||
state.has_key?(name) ||
default_state.has_key?(name)
end
|
#state ⇒ Object
17
18
19
|
# File 'lib/einhorn.rb', line 17
def state
@state ||= default_state
end
|
#state=(v) ⇒ Object
21
22
23
|
# File 'lib/einhorn.rb', line 21
def state=(v)
@state = v
end
|