Constructor

suggest change

A 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'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents