BernardK

BernardK

Programming Ruby 3.2 (5th Edition): B2.0 page 455, completing Table 13—Ruby operators

@noelrappin

page 455, what about completing Table 13—Ruby operators with :: and . ?

I was surprised not to find the scope resolution operator and the method access operator. A long search in the Internet shows either copies of the Pickaxe, or of O’Reilly’s book, The Ruby Programming Language, or various personal interpretations. Already in 2014 somebody complained that is was difficult to find a reliable Ruby operator precedence table.

I would place the method invocation operator . between [] and **.

a = [1, 2, 3]
print 'a = ', a; puts
puts "a[-1].succ = #{a[-1].succ}"
puts "3 ** 2.succ = #{3 ** 2.succ}"
puts "1 + 2.succ = #{1 + 2.succ}"

produces

a = [1, 2, 3]
a[-1].succ = 4
3 ** 2.succ = 27
1 + 2.succ = 4

I don’t know where to place the scope resolution operator which is special in the sense that it only connects an expression returning a module name and another constant (page 265) :

The thing to the left must be a class or module, and the thing to the right is a constant defined in that class or module.

O’Reilly’s book page 89 :

In addition to simple references like this one, constant references can also be compound expressions. In this case, :: is used to separate the name of the constant from the class or module in which it is defined. The lefthand side of the :: may be an arbitrary expression that evaluates to a class or module object. (Usually, however, this expression is a simple constant reference that just names the class or module.) The righthand side of the :: is the name of a constant defined by the class or module.

First Post!

noelrappin

noelrappin

Author of Modern Front-End Development for Rails

The canonical source for Ruby operator precedence is precedence - Documentation for Ruby 3.3 – that doesn’t have scope or method access (probably because the parser doesn’t treat them like operators). The canonical source doesn’t have [] either, because that’s really just a method call.

I confess to being a little unsure what to do – I think the table should match the official docs, but there’s more to how the Ruby parser works than operator precedence.

Popular Pragmatic Bookshelf topics Top

brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New

Other popular topics Top

malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
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
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
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
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1134 25464 754
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
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: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

Sub Categories: