BernardK

BernardK

Programming Ruby 3.2 (5th Edition): B1.0 page 240, short option with/without space

@noelrappin

page 240, last paragraph, lines 5-7 : the short option can have a space

… … … … … … … … … … … … … … … … … … … … … There’s one slight bit of weirdness here, which is
that a required argument is separated from a long option by a space but is flush against a
short option, so -xTHING

From the doc and experimentation, the marker can be separated by a space from the short option (it MUST be separated from a long option).

parser.on('-x XXX' … or parser.on('-xXXX' … have the same effect.

require "optparse"

parser = OptionParser.new

parser.on('-x XXX', '--xxx', 'Required argument via short name') do |value|
  puts "option -x is '-x XXX'"
end

parser.on('-zZZZ', '--zzz', 'Required argument via short name') do |value|
  puts "option -z is '-zZZZ'"
end

parser.parse!
% ruby -w rubyworld/option_doc.rb --help
Usage: option_doc [options]
    -x, --xxx XXX                    Required argument via short name
    -z, --zzzZZZ                     Required argument via short name

% ruby -w rubyworld/option_doc.rb -x x
option -x is '-x XXX'
% ruby -w rubyworld/option_doc.rb -z x
option -z is '-zZZZ'

First Post!

noelrappin

noelrappin

Author of Modern Front-End Development for Rails

Interesting, I must have misinterpreted the documentation. Thanks!

Popular Pragmatic Bookshelf topics Top

brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Sub Categories: