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.

Popular Prag Prog topics Top

New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
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
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
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
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
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
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
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

Latest in PragProg

View all threads ❯