Method Definition

def defname <(param) >     body end def defname <(param)> = expression defname methodname | expr.methodname

The defname contains the name of the method and optionally an expression defining the context in which the method is valid, the most common expression here is self, as in def self.method_name, but the expression can be any Ruby object.

A methodname is either a redefinable operator (see Table 19, Ruby operators (high to low precedence)) or a name. If methodname is a name, it starts with a letter or underscore optionally followed by uppercase and lowercase letters, underscores, and digits. A method can start with an uppercase letter, but that’s normally only done for the conversion methods in Kernel. A methodname ...

Get Programming Ruby 3.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.