1

I have a ruby bin I'd like to pass information to in this fashion:

some_text | ./bin/my_ruby_bin

where some_text will be accessible by ARGV

is this possible with ruby + shell or am I taking the wrong approach here?

random-forest-cat
  • 33,652
  • 11
  • 120
  • 99

1 Answers1

1

Here is simple solution that works for my cause, but it appears there are many ways to do this:

# ./bin/my_ruby_bin
#!/usr/bin/env ruby -n
puts "hello: #{$_}"

notice the -n flag

from command line:

echo 'world' | ./bin/my_ruby_bin
# => hello world

More on ruby -n

ruby -h
-n assume 'while gets(); ... end' loop around your script
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99