Basically you should learn #filename . One way to do this:
if ARGF.filename != "-" puts ARGF.read else puts "no redirect." end
And this is a more complete form:
#!/usr/bin/env ruby if ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?) puts ARGF.read else puts "No redirect." end
Other:
#!/usr/bin/env ruby if not STDIN.tty? and not STDIN.closed? puts STDIN.read else puts "No redirect." end
source share