Wednesday, May 30, 2007

Stupid Ruby Behaviors: Episode 1 (The Injury)

Because only "moon faced" kids like me would ever write a script that both read from STDIN and use ARGV

franz-macbook:~ mdfranz$ ruby moonface.rb
ddddddd
ddddddd
franz-macbook:~ mdfranz$ ruby moonface.rb me
moonface.rb:2:in `gets': No such file or directory - me (Errno::ENOENT)
from moonface.rb:2

mefranz-macbook:~ mdfranz$ cat moonface.rb
print ARGV
moonface = gets
print moonface

What gives? See gets documentation for the answer.

The solution is to use $stdin.gets

No comments: