Last Updated
Viewed 28 Times
     

I was reading documentation here https://ruby-doc.org/stdlib-2.6.3/libdoc/find/rdoc/Find.html and came accross this syntax which I was not famiiar with, in particular this line:

if File.basename(path)[0] == ?.

The code is obviously doing comparison, but not sure how this works.

This question already has an answer here:

I know that to use class inheritance in Ruby, the following syntax is used:

class MyNewClass < SomeClass
...
end

I also know that nesting in namespaces is identified using :::

class SomeNameSpace::MyNewClass < SomeNameOtherSpace::SomeClass 
...
end

However, what does the following syntax mean?

class SomeNameSpace::MyNewClass < ::SomeClass 
...
end

I expect that ::SomeClass (so without anything before the ::)is a shorthand for something, but what exactly does it mean?

In the following ruby example, what does the & represent? Is it along the line of += in a loop?

payments.sum(&:price)

Thanks,

Rich

I just came across this code:

@board=Array.new(7){Array.new(7)}

I've never seen this syntax for an array in ruby and I couldn't find much on it after a search. I don't really get what's going on with the curly braces here. I was hoping someone could just give me a brief explanation. Thanks!

Similar Question 4 (3 solutions) : What does :: (double colon) mean in Ruby? [duplicate]

Similar Question 5 (3 solutions) : what does “$&” mean in Ruby

Similar Question 6 (4 solutions) : What does $/ mean in Ruby?

Similar Question 9 (4 solutions) : What does the |variable| syntax mean?

cc