Class: TouristGuide::Tour

Inherits:
Object
  • Object
show all
Defined in:
lib/tourist_guide/tour.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_hash) ⇒ Tour

Returns a new instance of Tour.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tourist_guide/tour.rb', line 5

def initialize(attr_hash)
  # attr_hash.each do |attribute, v|
  # self.name= attribute(:name)
  # self.address= attribute(:address)
  # self.description= attribute(:description)

  # self.send "name=", "John Smith"
  # equivalent to
  # self.name = "John Smith"

  attr_hash.each do |attribute, v|
    self.send("#{attribute}=",v)

  end
  @@all << self
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



22
23
24
# File 'lib/tourist_guide/tour.rb', line 22

def self.all
  @@all
end

.clearObject

to delete duplicated & previous lists



33
34
35
# File 'lib/tourist_guide/tour.rb', line 33

def self.clear
 @@all =[]
end

.create_from_collection(array) ⇒ Object



26
27
28
29
30
# File 'lib/tourist_guide/tour.rb', line 26

def self.create_from_collection(array)
  array.each do |hash|
    self.new(hash)
  end
end