Method: Restaurant#initialize
- Defined in:
- lib/restaurant.rb
#initialize(restaurant) ⇒ Restaurant
Returns a new instance of Restaurant.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/restaurant.rb', line 6 def initialize(restaurant) location = restaurant.location coordinate = location.coordinate [restaurant, location, coordinate].each do |instance| instance.instance_variables.each do |variable| instance_has = instance.instance_variable_defined?(variable) self_has = self.instance_variables.find(variable) if instance_has && self_has if variable.to_s == "@categories" categories = instance.categories .map {|category| Category.find_by_title(category[0])} .compact @categories = categories categories.each {|category| category.restaurants << self} else self.instance_variable_set(variable, instance.instance_variable_get(variable)) end end end end @@all << self end |