Module: PlainAccessors::ClassMethods

Defined in:
lib/roundtrip_xml/plain_accessors.rb

Instance Method Summary collapse

Instance Method Details

#plain_accessor(name, matcher = /(\S*)/) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/roundtrip_xml/plain_accessors.rb', line 8

def plain_accessor(name, matcher = /(\S*)/)
  @plain_accessors ||= {}
  @plain_accessors[name] = matcher
  attr_writer name
  define_method(name) do
    val = instance_variable_get "@#{name}"
    val
    # @plain_accessors is actually nil here
    # val.nil? ? @plain_accessors[name] : val
  end
end

#plain_accessors(hash = false) ⇒ Object



20
21
22
23
# File 'lib/roundtrip_xml/plain_accessors.rb', line 20

def plain_accessors(hash = false)
  return @plain_accessors || {} if hash
  (@plain_accessors && @plain_accessors.keys) || []
end