Module: Agrippa::MutableHash::ClassMethods

Includes:
AccessorMethods
Defined in:
lib/agrippa/mutable_hash.rb

Instance Method Summary collapse

Methods included from AccessorMethods

#state_accessor, #state_reader, #state_writer

Instance Method Details

#__define_state_reader(key, original_caller, options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/agrippa/mutable_hash.rb', line 18

def __define_state_reader(key, original_caller, options)
    name = ::Agrippa::Methods.name(key, options)
    file, line = original_caller.first.split(':', 2)
    line = line.to_i
    spec = "def #{name}; @state[:#{key}]; end"
    module_eval(spec, file, line)
    self
end

#__define_state_writer(key, original_caller, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/agrippa/mutable_hash.rb', line 27

def __define_state_writer(key, original_caller, options)
    name = ::Agrippa::Methods.name(key, options)
    name = ::Agrippa::Methods.name(name, prefix: "set") \
        unless (options[:prefix] == false)
    file, line = original_caller.first.split(':', 2)
    line = line.to_i
    spec = "def #{name}(v); @state[:#{key}] = v; self; end"
    module_eval(spec, file, line)
    mark_as_command(name)
    self
end