Reputation: 1998
In Ruby, are there any methods that are reserved or have default meanings? I recently discovered that initialize
is one. Are there any others that I should be aware of when naming my methods? (VI is not giving me the coloring clues that other IDEs give for reserved names.)
In particular, names that have meaning in other languages like run
, main
, toString
, onExit
, etc.
Upvotes: 0
Views: 1454
Reputation: 4398
Also check out the list of reserver keywords here
If you're working in Rails, you may also want to take a look at this list
Upvotes: 2
Reputation: 7266
Despite nothing prevents declaring methods like public
or private
, I highly do not recommend doing so with any of the method names defined in core classes, such as Object
and Module
. Otherwise weird things can happen:
class Message
def self.private
puts 'private'
end
private
end
Message.private
Output:
private private
Private class method of a class Module
was redefined as public.
Upvotes: 0
Reputation: 70929
You can always see a list of the methods implemented by default for every class:
class Try
end
t = Try.new
puts t.methods.sort
EDIT: actually you may also want to look at the private methods (where initialize
is):
puts t.private_methods.sort
Upvotes: 2