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!

Where Next?

Popular Pragmatic Bookshelf topics Top

simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Sub Categories: