Class: Person

Inherits:
Object show all
Defined in:
lib/person.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, birthdate, address) ⇒ Person

Returns a new instance of Person.



4
5
6
# File 'lib/person.rb', line 4

def initialize(name, birthdate, address)
  @name, @birthdate, @address = name, birthdate, address
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



2
3
4
# File 'lib/person.rb', line 2

def address
  @address
end

#birthdateObject

Returns the value of attribute birthdate.



2
3
4
# File 'lib/person.rb', line 2

def birthdate
  @birthdate
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/person.rb', line 2

def name
  @name
end

Instance Method Details

#to_xml(wax) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/person.rb', line 8

def to_xml(wax)
  # Chaining approach
  #wax.start('person').attr('birthdate', @birthdate).child('name', @name)
  #@address.to_xml(wax)
  #wax.end!

  # Non-chaining approach
  # Put the current object in a local variable
  # so it can be accessed in the block passed to the write method.
  person = self
  wax.write do
    start 'person'
    attr 'birthdate', person.birthdate
    child 'name', person.name
    person.address.to_xml(self) # self is the WAX object here
    end!
  end
end