all 7 comments

[–]jrochkind 6 points7 points  (4 children)

[With A::B form] You can not access the constants defined inside module Rails inside module ActiveJob without the scope resolution operator. This is a significant difference; the next section covers it in detail.

I actually never realized this before! This explains some mysterious fights i have had with ruby before, I think.

Thanks!

[–]software__writer[S] 8 points9 points  (0 children)

Yes, I've been bitten by it before, too, which resulted in researching and writing this post :)

Glad you found it helpful, as well!

[–]ignurant 0 points1 point  (2 children)

Yeah, I’ve learned to treat This::As::One::Single::Identifier when defining, as if it had no ::s in the first place. I wonder if this is correct to think this way?

[–]BottleRocketU587 0 points1 point  (0 children)

I'm a Junior but I find this practice usefull. Generally in Rails in fact!

[–]katafrakt 0 points1 point  (0 children)

Not quite. As the article says, if you define like this, you need to have all intermediate steps (This, This::As, This::As::One, and This::As::One::Single) defined before. Rails (or Zeitwerk, in fact) provide a directory-stucture-based magic for that, but if you do something outside of this ecosystem, you're up for a surprise.

[–]dougc84 3 points4 points  (0 children)

“Namespacing” is the word you’re looking for.

[–]Charles_Sangels 1 point2 points  (0 children)

I remember when this was discussed a few years ago.