Defining a variable from the command prompt

I have a script that sends emails out to my company, and I would like
to be able to run it by saying (from the command prompt):

sendemail.rb “this is my message”

then it would take “this is my message” and use that as @msg or
something. I know its possible, but I’m still pretty new to Ruby and not
sure how to do this.

Any help is appreciated!


  • Jeff M.

sendemail.rb “this is my message”

faq. research on ARGV


C:\family\ruby>cat test.rb
msg = ARGV[0] || “using default”
puts msg

using default

C:\family\ruby>test.rb “this is a test”
this is a test

kind regards -botp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs