From: Dave Thacker Date: 2007-12-23T04:13:20+09:00 Subject: Diagnosing error in command line input I'm working on a program (my first) that will need to read user input (a file name) from the command line. While looking for examples of reading command line input, I stumbled across this example(1) which I've cut and pasted, to see how it works. #!/usr/bin/ruby require 'readline' def prompt(prompt="> ") input = nil prompt += " " unless prompt =~ /\s$/ loop do input = Readline.readline(prompt, true) break if input.length > 0 end return input end apples = prompt("how many apples do you have?") pears = prompt("how many pears do you have?") nonsense = prompt("try my input history (up/down arrow)") printf "there are %d items in our input history\n", Readline::HISTORY When I run this I get: dthacker@buckbeak:~/learning/ruby$ ./test-cl-io.rb how many apples do you have? 3 how many pears do you have? 7 try my input history (up/down arrow) 5 ./test-cl-io.rb:18:in `printf': can't convert Object into Integer (TypeError) from ./test-cl-io.rb:18 I'm guessing that HISTORY is not the method I want to call. Is that my problem? Or is there a simple newbie syntax error I'm making? TIA Dave (1)http://beaver.net/slides/ruby/10-easy-pieces.html