From: vnpenguin@... Date: 2006-01-01T06:27:58+09:00 Subject: my stupid code ... Hi, I'm trying to write a small ruby script which accepts: 1. Input : File or $stdin 2. Output : File or $stdout This is my stupid code: #--------------------------------------------------------- def do_some_thing(str) # do some things over str end f_in = ARGV[0] f_out = ARGV[1] if f_out==nil fout = File.open(f_out,"w") end if f_in==nil $stdin.each { |line| if f_out==nil print do_some_thing(line) else fout.print do_some_thing(line) end } else File.open(f_in,"r").each {|line| if f_out==nil print do_some_thing(line) else fout.print do_some_thing(line) end } end fout.close if f_out!=nil #-------------------------------------------------------------------- Don't laugh at me :-) I'm learning Ruby so I would like to hear from you a better way to write this small code. Thank you in advance and Happy New Year !