Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created December 14, 2009 18:26
Show Gist options
  • Save defunkt/256280 to your computer and use it in GitHub Desktop.
Save defunkt/256280 to your computer and use it in GitHub Desktop.
Transparent stdin / stdout
class MyApp
attr_accessor :input, :output
def initialize
@input = $stdin
@output = $stdout
end
def prompt_user
user_selection = gets.chomp # => 'ponies'
puts "User selected: #{user_selection}" # Displays User selected: ponies
user_selection
end
def puts(*args)
@output.puts(*args)
end
def gets(*args)
@output.gets(*args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment