Module: Xrechnung::MemberContainer

Defined Under Namespace

Modules: ClassMethods Classes: Member

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/xrechnung/member_container.rb', line 3

def self.included(base)
  base.instance_variable_set :@members, {}
  base.extend ClassMethods
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/xrechnung/member_container.rb', line 19

def [](key)
  send(key)
end

#[]=(key, value) ⇒ Object



23
24
25
# File 'lib/xrechnung/member_container.rb', line 23

def []=(key, value)
  send("#{key}=", value)
end

#initialize(**kwargs) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/xrechnung/member_container.rb', line 8

def initialize(**kwargs)
  # initialize default values
  self.class.members.each do |name, member|
    self[name] = member.default.dup unless member.default.nil?
  end

  kwargs.each do |k, v|
    self[k] = v
  end
end