Objects are created from the class. Creating an object from a class is called instantiation.
We will actually create a class. Use the class syntax as follows:
sample.rb
class House
end
There is a rule to capitalize the beginning of the class name. With this description, I was able to define a minimal House class.
Next, we will create an instance (object) from the created House class. You can create an instance (object) by using the new method.
sample.rb
class House
end
House.new
To call a class, write the class name.
sample.rb
class House
end
House
Let's make sure the instance class is the House class.
sample.rb
class House
end
puts House.new.class
Execute sample.rb on the console, and if the output is as follows, the instance has been created correctly from the House class.
House
Recommended Posts