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?
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.
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.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With