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
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
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
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
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
New
AstonJ
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New

Sub Categories: