Created
February 15, 2012 12:04
-
-
Save ashbb/1835292 to your computer and use it in GitHub Desktop.
A sample snippet to use puts and gets on Green Shoes.
This file contains hidden or 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
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original code was written by Timothy.