The Ruby initialize method

Treasure class

The Initialize Method is useful for setting an object to automatically create a few basic attributes or methods when you a create a new object. 

In the image, you can see an example of a Class WITH an Initialize Method.

Without an Initialize Method, you must create separate methods to assign the attributes on your own:

class Thing

    def set_name (aName)

       @name = aName

    end

    def get_name

        return @name 

    end

| Back

Footerfull