BernardK

BernardK

Programming Ruby 3.2 (5th Edition): B1.0 page 23, alignment of hash

@noelrappin
In Programming Ruby 1.9, 2010 edition, this hash in page 21 was nicely aligned ;

inst_section = {
'cello'      => 'string',
'clarinet'   => 'woodwind',
'drum'       => 'percussion',
'oboe'       => 'woodwind',
'trumpet'    => 'brass',
'violin'     => 'string'
}

It’s just that I find that aligned identical things are more readable.

Same on pages 24-25 (page 23 of the 2010 book).

Regexp examples on page 27 : first line is not aligned, but could be :

/\d\d:\d\d:\d\d/     # a time such as 12:34:56
/Ruby.*Rust/       # Ruby, zero or more other chars, then Rust
/Ruby Rust/        # Ruby, exactly one space, and Rust
...
/Java (Ruby|Rust)/ # Java, a space, and either Ruby or Rust

Start of page 28 could be :

line = gets
newline = line.sub(/Python/, 'Ruby')    # replace first 'Python' with 'Ruby'
newerline = line.gsub(/Python/, 'Ruby') # replace every 'Python' with 'Ruby'

Bottom of page 29 :

animals = ["ant", "bee", "cat", "dog"]    # create an array    <<<<========
animals.each { |animal| puts animal }   # iterate over the contents

By the way thank you for spending a lot of time writing this book. As I am back to Ruby, I’m glad to have an updated version. My latest book is 12 years old and I prefer reading a book than constantly searching the Internet.

First Post!

noelrappin

noelrappin

Author of Modern Front-End Development for Rails

This is a deliberate choice to align all the code with the style choices of the Standard Ruby gem, which does not call for extra whitespace for alignment. (I sometimes find them more readable, but always find them difficult to maintain…)

Thanks for the suggestion and the kind words!

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
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
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
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
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1037 19435 386
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
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
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
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
New

Sub Categories: