Skip to content

Instantly share code, notes, and snippets.

@adayNU
Created June 7, 2017 22:05
Show Gist options
  • Save adayNU/cc5528a3f528c5e22150b6d55e66c917 to your computer and use it in GitHub Desktop.
Save adayNU/cc5528a3f528c5e22150b6d55e66c917 to your computer and use it in GitHub Desktop.
class Benihana
Courses = {
"Soup" => 10,
"Salad" => 10,
"Veggies and Shrimp" => 20,
"Fried Rice" => 25,
"Rocky's Choice" => 35
}
private_constant :Courses
def initialize
@sake_bomb_count = 0
@hunger_level = 100
end
def self.courses
Courses.keys
end
def eat_course(course)
if !Courses.include? course
puts "That's not a course they serve... How drunk are you, and where did you get that #{course}?!"
return nil
end
safe_eat(Courses[course])
end
def take_sake_bomb
@sake_bomb_count += 1
end
def hunger_level
return @hunger_level
end
def sake_bomb_count
return @sake_bomb_count
end
private
def safe_eat(course_cost)
if @hunger_level < course_cost
puts "You're too full, bro. Stop eating."
return nil
end
@hunger_level -= course_cost
end
end
@adayNU
Copy link
Author

adayNU commented Jun 7, 2017

Example usage:

andy = Benihana.new

Benihana.courses.each_with_index do |course, i|
  andy.eat_course(course)
  (i + 1).times { andy.take_sake_bomb }
end

puts "Hunger Level: #{andy.hunger_level}, Sake Bomb Count: #{andy.sake_bomb_count}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment