Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13862

What does def <<(path) mean in rails/ruby

While looking through gem file for Grackle, found this method:

def <<(path)
  self.path << path
end

What does it mean and do?

Upvotes: 0

Views: 208

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51151

It's a definition of << method, which could also be used in "operator" manner, like this:

a << path

It's commonly used syntax sugar in Ruby. In fact, if you do

2 + 4

you're really calling + method on 2 object with parameter of 4, like this:

2.+(4)

You can check on your own, that this last notation also works correctly.

Upvotes: 3

Related Questions