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.

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!