Object Oriented Programming

Instantiation in Ruby

Used to create an object instance from a class (instantiate).


Syntax
identifier = className.new(passedParameters)

Notes

Input requirements are taken from the constructor. A class can have multiple constructors with different numbers of input parameters and types, to create different objects.

An instance of a class is called an object.


Example
#class definition
class Car
     def initialize(make)
         @make = make
     end
end

#class instantiation
myCar = new.Car("Honda")

< Constructor   |   Inheritance >

© 2018 SyntaxDB. All Rights Reserved.