Ruby Command Line Options - verbose mode ON and placing code into Imput Loop

StackOverflow https://stackoverflow.com/questions/14273956

  •  14-01-2022
  •  | 
  •  

سؤال

Can any body tell how the below three options differs from each other in Ruby?

Part-I

  • --verbose
  • -v
  • -w

Part-II

  • -n
  • -p

All are doing the same job which is verbose mode ON. But logically how are they differs from each other?

Thanks,

هل كانت مفيدة؟

المحلول

-v is just a shorter way of writing --verbose, so they are the same thing. -w turns on warnings, see http://www.caliban.org/ruby/rubyguide.shtml#warnings for more info about those.

Part 2:

-n and -p are not related to verbosity. They just loop your ruby script.

Run the following from your terminal:

ruby -n -e "puts 'hello world'"

Now press the enter key a few times. You should see:

hello world

hello world

hello world

Now do the same for -p:

ruby -p -e "puts 'hello world'"

This just repeats what you typed before pressing enter.

asdf
hello world
asdf

hello world

asdfs
hello world
asdfs
34644
hello world
34644
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top