Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person
- attr_accessor :name,:age,:drink
- def cry
- puts "#{self.name}: Whaaa-Whaaa"
- end
- def laugh
- puts "#{self.name}: hahahaha great"
- end
- def ask_name(person)
- puts self.name+": What is your name?"
- puts "#{person.name}: My name is #{person.name}"
- person.name #the return keyword is not needed
- end
- def ask_age(person)
- puts self.name+": How old are you?"
- person.say_age
- person.age #the return keyword is not needed
- end
- def say_age
- puts "#{self.name}: I am #{self.age} years old"
- end
- def order(bartender,drink)
- if bartender.class == Bartender
- puts self.name+": I would like a "+drink
- @drink = bartender.give(self,drink)
- @drink.nil? ? cry : laugh
- else
- puts "#{self.name}: Oh sorry! I thought you were a bartender"
- end
- end
- end
- class Bartender < Person
- $drinks = ["Beer","Whiskey","Rum","Mojito"]
- def give(person,drink)
- if(person.age.to_i >=18)
- if $drinks.include?(drink)
- puts "#{self.name}: Here is your #{drink}"
- drink
- else
- puts "#{self.name}: I dont have any #{drink}"
- end
- else
- puts "#{self.name}: You are a minor, you cant buy alcohol"
- nil
- end
- end
- def say_age
- puts "#{self.name}: I dont say my age im a bartender"
- end
- end
- john = Bartender.new
- john.age = 35
- john.name = "John Petrucci"
- steve = Person.new
- steve.age = 23
- steve.name = "Steve Vai"
- kid = Person.new
- kid.age = "16"
- kid.name = "Joe Satriani"
- steve.ask_name(john)
- steve.ask_age(john)
- steve.order(john,"Beer")
- kid.order(john,"Whiskey")
- steve.ask_age(kid)
Add Comment
Please, Sign In to add comment