Module: HattrAccessor

Defined in:
lib/madhattr/hattr_accessor.rb

Instance Method Summary collapse

Instance Method Details

#hattr_accessor(source, *keys) ⇒ Object Also known as: hattr_accessors



20
21
22
23
# File 'lib/madhattr/hattr_accessor.rb', line 20

def hattr_accessor(source, *keys)
  hattr_reader source, *keys
  hattr_writer source, *keys
end

#hattr_reader(source, *keys) ⇒ Object Also known as: hattr_readers



2
3
4
5
6
7
# File 'lib/madhattr/hattr_accessor.rb', line 2

def hattr_reader(source, *keys)
  ensure_readable source
  keys.each do |key|
    define_method(key) { send(source).fetch(key) }
  end
end

#hattr_writer(source, *keys) ⇒ Object Also known as: hattr_writers



10
11
12
13
14
15
16
17
# File 'lib/madhattr/hattr_accessor.rb', line 10

def hattr_writer(source, *keys)
  ensure_readable source
  keys.each do |key|
    define_method("#{key}=") do |value|
      send("#{source}").store(key, value)
    end
  end
end