Returns the name of this class.
Returns the name of this class.
Defines new_method as an alias of old_method.
Defines an #== method by comparing the given fields.
Defines a #hash method computed from the given fields.
Delegate method to to_object.
Forwards missing methods to delegate.
Defines getter methods for each of the given arguments.
Defines raise-on-nil and nilable getter methods for each of the given arguments.
Defines query getter methods for each of the given arguments.
Defines property methods for each of the given arguments.
Defines raise-on-nil property methods for each of the given arguments.
Defines query property methods for each of the given arguments.
Defines setter methods for each of the given arguments.
Returns the name of this class.
String.name #=> "String"Returns the name of this class.
String.name #=> "String"Defines new_method as an alias of old_method.
This creates a new method new_method that invokes old_method.
Note that due to current language limitations this is only useful when neither named arguments nor blocks are involved.
class Person
getter name
def initialize(@name)
end
alias_method full_name, name
end
person = Person.new "John"
person.name #=> "John"
person.full_name #=> "John"Defines a #hash method computed from the given fields.
class Person
def initialize(@name, @age)
end
# Define a hash method based on @name and @age
def_hash @name, @age
endDelegate method to to_object.
Note that due to current language limitations this is only useful when neither named arguments nor blocks are involved.
class StringWrapper
def initialize(@string)
end
delegate downcase, @string
delegate gsub, @string
end
wrapper = StringWrapper.new "HELLO"
wrapper.downcase #=> "hello"
wrapper.gsub(/E/, "A") #=> "HALLO"Forwards missing methods to delegate.
class StringWrapper
def initialize(@string)
end
forward_missing_to @string
end
wrapper = StringWrapper.new "HELLO"
wrapper.downcase #=> "hello"
wrapper.gsub(/E/, "A") #=> "HALLO"Defines getter methods for each of the given arguments.
Writing:
class Person
getter name
end
Is the same as writing:
class Person
def name
@name
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
getter :name, "age"
endDefines raise-on-nil and nilable getter methods for each of the given arguments.
Writing:
class Person
getter! name
end
Is the same as writing:
class Person
def name?
@name
end
def name
@name.not_nil!
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
getter! :name, "age"
endDefines query getter methods for each of the given arguments.
Writing:
class Person
getter? name
end
Is the same as writing:
class Person
def name?
@name
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
getter? :name, "age"
endDefines property methods for each of the given arguments.
Writing:
class Person
property name
end
Is the same as writing:
class Person
def name=(@name)
end
def name
@name
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
property :name, "age"
endDefines raise-on-nil property methods for each of the given arguments.
Writing:
class Person
property! name
end
Is the same as writing:
class Person
def name=(@name)
end
def name?
@name
end
def name
@name.not_nil!
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
property! :name, "age"
endDefines query property methods for each of the given arguments.
Writing:
class Person
property? name
end
Is the same as writing:
class Person
def name=(@name)
end
def name?
@name
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
property? :name, "age"
endDefines setter methods for each of the given arguments.
Writing:
class Person
setter name
end
Is the same as writing:
class Person
def name=(@name)
end
end
The arguments can be string literals, symbol literals or plain names:
class Person
setter :name, "age"
end