My name is Mason Ellwood, and I’m currently working on Flatiron School’s Online Full Stack Web Development Program. Each week, I’ll be writing about my experience, what I’m learning, and tips on learning to code.
So here it is, one of the biggest pains in the butt I have ever experienced. Object Oriented Programming.
“An object-oriented approach to application development makes programs more intuitive to design, faster to develop, more amenable to modification, and easier to understand” – Apple inc.
An object in code is basically a “thing” that holds all the data and all the logic required to complete a task. Ruby, in this particular circumstance comes out of the box with a few built-in objects such as integers, strings, and arrays. To create a new object, Ruby uses the “class” keyword.
Classes and Instances
A class is basically a blueprint that defines how to build and object. A Ruby class both contains the instructions for creating new objects and has the ability to create those objects.
Class names are camel-case (Ex: NewClass) because they are stored as Ruby constants.
The NewClass is defined with the class keyword, followed by the class name and closed with “end”. The body is between these keywords. On the NewClass class, we call the .new method and that will instantiate (bringing a new object to life) a new NewClass. Each particular NewClass is an individual that was instantiated when we called NewClass.new. Each individual NewClass is an instance.
An instance is a single occurrence of an object. Instances refer to the individual object produced from the class.
Returned when calling the instance of the new class you have created will return the Ruby Object Notation. It is Ruby’s way of telling you that you are dealing with an object or instance of a particular class.
- NewClass: = the object of a particular class
- 0x07fb3b4826828 = where the object lies within the computer
This is a brief intro to Ruby Object Oriented Notation. This concept took me a while to grasp and get a hold of. If you understand Procedural Ruby that is it a little easier to grasp this concept. This allows your code to be more reusable and allows the ability to extend your application more quickly. Thank you for reading and I hope you learned something. I am still tackling this concept conceptually, so bare with me and I apologize in advance if the future post and a bit confusing.