Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby naming convention / double underscore / useful stuff

I know there is __FILE__, __LINE__, and __send__.

From the Delegator class there are __getobj__ and __setobj__.

Is there any other useful "strange" double underscore goodness present in the Ruby standard library?

like image 909
astropanic Avatar asked Jan 23 '14 23:01

astropanic


People also ask

What is the naming convention for a variable in Ruby on rails?

Rails use the same naming convention as Ruby (for a list of the Ruby naming conventions scroll down) with some additions: Variable - e.g. order_amount, total. Variables are named where all letters are lowercase and words are separated by underscores.

What do single and double underscores mean in Python variable names?

Single and double underscores have a meaning in Python variable and method names. Some of that meaning is merely by convention and intended as a hint to the programmer-and some of it is enforced by the Python interpreter.

What is the use of underscore and asterisk in Ruby?

Additionally, Ruby allows the combination of both underscore and asterisk which is especially useful when you need for instance the first and last element from an array. The asterisk is also used for dereferencing variables. Later on in function calls it will be used to pass the array content to a function as parameters.

How many different underscore naming conventions are there?

At the end of the article you’ll also find a brief “cheat sheet” summary of the five different underscore naming conventions and their meaning, as well as a short video tutorial that gives you a hands-on demo of their behavior.


1 Answers

This is a complete list for Ruby 2.1:

  • __callee__ (Kernel)
  • __dir__ (Kernel)
  • __method__ (Kernel)
  • __id__ (BasicObject)
  • __send__ (BasicObject)
  • __ENCODING__ (keyword)
  • __LINE__ (keyword)
  • __FILE__ (keyword)

From delegate:

  • __getobj__ (Delegator)
  • __setobj__ (Delegator)
  • __getobj__ (SimpleDelegator)
  • __setobj__ (SimpleDelegator)

From drb:

  • __drbref
  • __drburi

From irb:

  • __evaluate__
  • __exit__

From tk:

  • All the methods start with a double underscore
like image 165
Agis Avatar answered Sep 30 '22 19:09

Agis