Skip to content

Instantly share code, notes, and snippets.

@weatheredwatcher
Created January 30, 2011 21:08
Show Gist options
  • Save weatheredwatcher/803254 to your computer and use it in GitHub Desktop.
Save weatheredwatcher/803254 to your computer and use it in GitHub Desktop.
class Pizza
def initialize(&factory)
@factory = factory
end
def bake
@factory.call
end
end
a = Pizza.new { puts 'This is a Cheese Pizza' }
a.bake #=> Making A Regular Cheese Pizza
b = Pizza.new { puts 'This is a Pepperoni Pizza' }
b.bake #=> Making a Pepperoni Pizza
c = Pizza.new { puts 'This is a Deluxe Pizza' }
c.bake #=> Making a Deluxe Pizza
system("stty raw -echo") #=> Raw mode, no echo
char = STDIN.getc
until char == 113
case char
when 97
a.bake
when 98
b.bake
when 99
c.bake
when 113
else
"error"
end
char = STDIN.getc
end
system("stty -raw echo") #=> Reset terminal mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment