简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM