Search code examples
rubynaming-conventions

Ruby variable name with double underscores


Sometimes I see variable names with double underscore in the beginning and the end. For example:

Article.__elasticsearch__

Is there some naming convention related to double underscores in Ruby variable names?


Solution

  • An initial underscore or double underscore basically indicates "special/avoid overwrite" --meaning it's meant to reduce the likelihood that someone else might define a method/attribute of the same name. The most common occurrence is __send__.

    From Ruby Forum