Constructor
suggest changeA class has one constructor method, initialize. Ruby calls it when a new instance is created.
class Customer
attr_reader :name
def initialize(name)
@name = name.capitalize
end
end
sarah = Customer.new('sarah')
sarah.name #=> 'Sarah'
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents