Module: Agrippa::Mutable::InstanceMethods

Defined in:
lib/agrippa/mutable.rb

Instance Method Summary collapse

Instance Method Details

#chain(state) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
49
50
# File 'lib/agrippa/mutable.rb', line 45

def chain(state)
    raise(ArgumentError, "#set requires a Hash") \
        unless state.respond_to?(:each_pair)
    state.each_pair { |key, value| store(key, value) }
    self
end

#fetch(key, default = nil) ⇒ Object



57
58
59
# File 'lib/agrippa/mutable.rb', line 57

def fetch(key, default = nil)
    instance_variable_get("@#{key}") || default
end

#initialize(state = nil) ⇒ Object



40
41
42
43
# File 'lib/agrippa/mutable.rb', line 40

def initialize(state = nil)
    chain(default_state) if respond_to?(:default_state)
    chain(state) unless state.nil?
end

#store(key, value) ⇒ Object



52
53
54
55
# File 'lib/agrippa/mutable.rb', line 52

def store(key, value)
    instance_variable_set("@#{key}", value)
    self
end