Created
February 6, 2018 18:09
-
-
Save nmajor/ec4afecd3da4e82c9875cf4fd05b9abd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Food | |
attr_accessor :people_who_like_me | |
def initialize(attr = {}) | |
@name = attr[:name] | |
@finger_food = true | |
@people_who_like_me = [] | |
end | |
def name | |
@name | |
end | |
def eat | |
puts "I ate it all" | |
end | |
def cook | |
puts "Food is cooked" | |
end | |
def print_name | |
puts "my dish name is #{name}" | |
end | |
def inspect_self | |
p self | |
end | |
# bitoque.add_person(me) | |
def add_person(person) | |
person.food_i_like << self | |
@people_who_like_me << person | |
end | |
end | |
class Person | |
attr_accessor :food_i_like | |
def initialize(attr = {}) | |
@name = attr[:name] | |
@food_i_like = [] | |
end | |
def name | |
@name | |
end | |
end | |
me = Person.new(name: 'Nick Major') | |
bitoque = Food.new(name: 'Bitoque') | |
bifana = Food.new(name: 'Bifana') | |
bitoque.add_person(me) | |
p bitoque.people_who_like_me | |
p me.food_i_like | |
# p bitoque | |
# bitoque.inspect_self | |
# class Liquid | |
# def drink | |
# "You drank the liquid" | |
# end | |
# def evaporate | |
# "No more liquid" | |
# end | |
# def super_duper_drink | |
# "I am the super duper portuguese speaker!!" | |
# end | |
# end | |
# class Alcohol < Liquid | |
# def drink | |
# "#{super} You are drunk" | |
# end | |
# def super_duper_drink | |
# super | |
# end | |
# end | |
# class Beer < Alcohol | |
# def drink | |
# "#{super} Free in the fridge" | |
# end | |
# def super_duper_drink | |
# end | |
# end | |
# beer1 = Beer.new | |
# p beer1.drink | |
# p beer1.super_duper_drink | |
# class Animal | |
# def initialize(attr = {}) | |
# @mammal = attr[:mammal] | |
# end | |
# def mammal? | |
# false | |
# end | |
# def bird? | |
# false | |
# end | |
# end | |
# class Dog < Animal | |
# def mammal? | |
# true | |
# end | |
# end | |
# class Cat < Animal | |
# def mammal? | |
# true | |
# end | |
# end | |
# class Parakeet < Animal | |
# def bird? | |
# true | |
# end | |
# end | |
# pets = [ | |
# Dog.new, | |
# Dog.new, | |
# Cat.new, | |
# Parakeet.new, | |
# Parakeet.new | |
# ] | |
# mammal_pets = pets.select do |pet| | |
# pet.mammal? | |
# end | |
# # mammal_pets = pets.map do |pet| | |
# # if pet.mammal? | |
# # pet | |
# # end | |
# # end | |
# # mammal_pets = [] | |
# # pets.each do |pet| | |
# # if pet.mammal? | |
# # mammal_pets << pet | |
# # end | |
# # end | |
# p mammal_pets | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment