Elia Schito

Get input in Rake Tasks

In Programming, rake, Ruby, Ruby snippets, Snippets on November 7, 2008 at 2:47 pm

This won’t work:

cvs_username = gets

to get it working you have to ask input from STDIN:

cvs_username = STDIN.gets

And this is a helper method:

def ask message
print message
STDIN.gets.chomp
end
# ...
cvs_username = ask('Please insert your CVS username')

  1. works like a charm.

  2. nice helper..

    My ‘fork’ lol:

    def ask message, default_response=”
    print “#{message} ”
    response = STDIN.gets.chomp
    response.blank? ? default_response : response
    end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: