Created
November 24, 2014 07:52
-
-
Save JoshCheek/d740052fe9e2c666d15c to your computer and use it in GitHub Desktop.
Fun times at Rubyconf!
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 Treehouse | |
def initialize(ladder, happyduckslide, sadsharkslide) | |
@ladder = ladder # => #<StringIO:0x007fb29c0c8a68> | |
@happyduckslide = happyduckslide # => #<IO:<STDOUT>> | |
@sadsharkslide = sadsharkslide # => #<IO:<STDERR>> | |
end # => :initialize | |
def ride | |
name = @ladder.gets().chomp() # => "Josh", "Anna Marie" | |
if rand(2) == 1 # => true, false | |
@happyduckslide.puts("#{name} climbs the ladder, slides into the lake, and swims with the ducks!") # => nil | |
else | |
@sadsharkslide.puts("#{name} climbs the ladder, slides into the ocean, and gets devoured by the shark!") # => nil | |
end # => nil, nil | |
end # => :ride | |
end | |
require 'stringio' # => true | |
ladder = StringIO.new "Josh\nAnna Marie" # => #<StringIO:0x007fb29c0c8a68> | |
happyduckslide = $stdout # => #<IO:<STDOUT>> | |
sadsharkslide = $stderr # => #<IO:<STDERR>> | |
treehouse = Treehouse.new(ladder, happyduckslide, sadsharkslide) # => #<Treehouse:0x007fb29c0c8518 @ladder=#<StringIO:0x007fb29c0c8a68>, @happyduckslide=#<IO:<STDOUT>>, @sadsharkslide=#<IO:<STDERR>>> | |
treehouse.ride # => nil | |
treehouse.ride # => nil | |
# There's a super cool new treehouse down the block. | |
# It has a ladder that takes a person into the house and two slides that drops them out into a lake. | |
# Anyone can go for a slide ride. | |
# | |
# >> Josh climbs the ladder and slides into the lake! | |
# !> Anna Marie climbs the ladder and slides into the lake! |
codesliced
commented
Nov 24, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment