Skip to content

Instantly share code, notes, and snippets.

@ashbb
Created February 15, 2012 12:04
Show Gist options
  • Select an option

  • Save ashbb/1835292 to your computer and use it in GitHub Desktop.

Select an option

Save ashbb/1835292 to your computer and use it in GitHub Desktop.
A sample snippet to use puts and gets on Green Shoes.
require 'green_shoes'
class ShoesIO < StringIO
def initialize app, stdout, *args
@app, @stdout = app, stdout
super *args
end
def gets
res = @app.ask @stdout.string.split("\n").last
res.to_s + "\n"
end
end
Shoes.app do
stack do
@console = edit_box
@button = button "Ask Name"
end
$stdout = StringIO.new
$stdin = ShoesIO.new self, $stdout, ''
e = every do |i|
@console.text = $stdout.string
end
@button.click do
puts "What is your name?"
ans = gets.chomp
ans = ans == '' ? 'no answer' : ('Name: ' + ans)
puts ans
end
end
@ashbb
Copy link
Author

ashbb commented Feb 15, 2012

Original code was written by Timothy.

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