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!

Popular Pragmatic Bookshelf topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
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
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
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
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Other popular topics Top

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
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1134 25464 754
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Sub Categories: