SlideShare a Scribd company logo
Who am I
●

Juan Leal
–

Rubyist and Rails Developer since 2007

–

Worked at Equifax and Pragmatic Programmers

–

Currently employed at Hiplogiq
What We'll Cover
●

A review of Classes and Objects

●

Some basics of classes in Ruby

●

●

Some background info regarding classes in
Ruby.
Using Ruby's class Class.
A review of Classes and Objects
What's a class? - let's review
●

●

blueprint or pattern for how we want to
construct something.
template defining the methods and variables in
a particular kind of object.
Classes vs Objects
●
●

●

It's important distinguish between the two.
Classes are instantiated into instances or
objects.
Objects and classes are not the same.
A real world analogy for example is that a
blueprint of a house would a class and actual
house would be an object.

Class

Object
Classes in Ruby, some basics
Defining a class

Here we define a class and
a method.
Inheritance
Here the class Bar inherits
from class Foo.
Define a Constructor
In Ruby one defines a
constructor through the
method initialize.
Here we've defined initialize
and have it take an
argument called 'name'.
Then we set an instance
variable to value of 'name'.
Ruby classes, some background information.
General points
●

In Ruby everything is object.

●

Objects are instances of a class.

●

Simple right?
Lets Look at Some Code

This is how we discover an object's class.

This is how we discover a class' parent class.
Classes in Ruby
In Ruby everything is an object. This
includes classes. As such a class in Ruby
is an instance of class Class.

But wait, if everything is an object
then that means Class is an object
too. And sure enough it is.

So if Class is an object, what is it an
instance of?
It's an instance of class Class. In
other words, it's an instance of itself.
Intro Ruby Classes Part I
So...
an instance of

class

Class
Class is an object.
Remember in Ruby everything is an object.
Class is an instance of class Class.
Remember all objects are instances of a class.

So the thing is, there really is nothing overly significant about
this. This relationships is just a result of the way the Ruby
object model was designed. It won't be on the final but it's stuff
that can be useful to know.
Using class Class.
The class Class
Let's take a look at what we can do with Class.

We can define classes.

We can do inheritance.
How I commonly use class Class
Many times when people need to
do a simple subclass they jam
their code on a single line as
shown in line :2.
It's valid ruby code but a little
unsightly. It resorts to using the
semicolon which separates the
commands.

My personal preference is to
subclass using class Class.
In Closing
●

●

There's quite a bit about classes which we have
not covered.
This will be an ongoing series so keep an eye
out for more to come.

●

Thank you for attending.

●

Twitter: @terminalbreaker
The End.

More Related Content

ODP
Constructors, Intro to Ruby Classes Part II
PPTX
Paca oops slid
PDF
Not So Foreign Functions
PPTX
JavaScript Beyond jQuery
ODP
JavaScript Object Oriented Programming Cheat Sheet
PPTX
Actor-based concurrency and Akka Fundamentals
PDF
Javascript for Intermediates
PPTX
Object Oriented Programming In JavaScript
Constructors, Intro to Ruby Classes Part II
Paca oops slid
Not So Foreign Functions
JavaScript Beyond jQuery
JavaScript Object Oriented Programming Cheat Sheet
Actor-based concurrency and Akka Fundamentals
Javascript for Intermediates
Object Oriented Programming In JavaScript

What's hot (20)

PDF
Model with actors and implement with Akka
PDF
05 ruby classes
PPTX
Object oriented programming in JavaScript
PPTX
On the path to become a jr. developer short version
PDF
Ruby Metaprogramming - OSCON 2008
PDF
Ruby — An introduction
PDF
Introduction to Object Oriented Javascript
PPT
The ruby programming language
KEY
Ruby's metaclass
PPT
Intro To Ror
PPTX
Ruby for .NET developers
PPTX
JavaScript - Zero To Hero - Class 1
PPTX
Ruby for PHP developers
PDF
Lets talk-about-js
PPTX
Java object
PPTX
Groovy / comparison with java
DOC
Java classes and objects interview questions
PPTX
Java scriptforjavadev part1
PPTX
Lec08 constructors
ODP
String interpolation
Model with actors and implement with Akka
05 ruby classes
Object oriented programming in JavaScript
On the path to become a jr. developer short version
Ruby Metaprogramming - OSCON 2008
Ruby — An introduction
Introduction to Object Oriented Javascript
The ruby programming language
Ruby's metaclass
Intro To Ror
Ruby for .NET developers
JavaScript - Zero To Hero - Class 1
Ruby for PHP developers
Lets talk-about-js
Java object
Groovy / comparison with java
Java classes and objects interview questions
Java scriptforjavadev part1
Lec08 constructors
String interpolation
Ad

Similar to Intro Ruby Classes Part I (20)

PDF
Aman kingrubyoo pnew
PPTX
Ruby OOP: Objects over Classes
DOCX
Ruby Interview Questions
PDF
The Ruby Object Model by Rafael Magana
PPTX
Abstraction in java [abstract classes and Interfaces
PPTX
Ruby object model - Understanding of object play role for ruby
PPTX
Object oriented javascript
PDF
Me, my self and IPython
PPTX
Object Oriented Programming 02b: Classes
DOCX
Object oriented programming tutorial
PDF
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
PDF
Class and Objects in object-oriented programming with Java
PDF
Ruby Metaprogramming 08
PPTX
Java OOPS Concept
DOCX
OOPS ABAP.docx
PPTX
Object Oriented Programming_Lecture 2
PPTX
JavaScript OOPS Implimentation
PPTX
Chapter 7 java
PPT
Java script unleashed
PPTX
Introduction to Scala
Aman kingrubyoo pnew
Ruby OOP: Objects over Classes
Ruby Interview Questions
The Ruby Object Model by Rafael Magana
Abstraction in java [abstract classes and Interfaces
Ruby object model - Understanding of object play role for ruby
Object oriented javascript
Me, my self and IPython
Object Oriented Programming 02b: Classes
Object oriented programming tutorial
CS8392-OOPS-Printed-Notes-All-Units.pdf for students
Class and Objects in object-oriented programming with Java
Ruby Metaprogramming 08
Java OOPS Concept
OOPS ABAP.docx
Object Oriented Programming_Lecture 2
JavaScript OOPS Implimentation
Chapter 7 java
Java script unleashed
Introduction to Scala
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Intro Ruby Classes Part I

  • 1. Who am I ● Juan Leal – Rubyist and Rails Developer since 2007 – Worked at Equifax and Pragmatic Programmers – Currently employed at Hiplogiq
  • 2. What We'll Cover ● A review of Classes and Objects ● Some basics of classes in Ruby ● ● Some background info regarding classes in Ruby. Using Ruby's class Class.
  • 3. A review of Classes and Objects
  • 4. What's a class? - let's review ● ● blueprint or pattern for how we want to construct something. template defining the methods and variables in a particular kind of object.
  • 5. Classes vs Objects ● ● ● It's important distinguish between the two. Classes are instantiated into instances or objects. Objects and classes are not the same.
  • 6. A real world analogy for example is that a blueprint of a house would a class and actual house would be an object. Class Object
  • 7. Classes in Ruby, some basics
  • 8. Defining a class Here we define a class and a method.
  • 9. Inheritance Here the class Bar inherits from class Foo.
  • 10. Define a Constructor In Ruby one defines a constructor through the method initialize. Here we've defined initialize and have it take an argument called 'name'. Then we set an instance variable to value of 'name'.
  • 11. Ruby classes, some background information.
  • 12. General points ● In Ruby everything is object. ● Objects are instances of a class. ● Simple right?
  • 13. Lets Look at Some Code This is how we discover an object's class. This is how we discover a class' parent class.
  • 14. Classes in Ruby In Ruby everything is an object. This includes classes. As such a class in Ruby is an instance of class Class. But wait, if everything is an object then that means Class is an object too. And sure enough it is. So if Class is an object, what is it an instance of? It's an instance of class Class. In other words, it's an instance of itself.
  • 16. So... an instance of class Class Class is an object. Remember in Ruby everything is an object. Class is an instance of class Class. Remember all objects are instances of a class. So the thing is, there really is nothing overly significant about this. This relationships is just a result of the way the Ruby object model was designed. It won't be on the final but it's stuff that can be useful to know.
  • 18. The class Class Let's take a look at what we can do with Class. We can define classes. We can do inheritance.
  • 19. How I commonly use class Class Many times when people need to do a simple subclass they jam their code on a single line as shown in line :2. It's valid ruby code but a little unsightly. It resorts to using the semicolon which separates the commands. My personal preference is to subclass using class Class.
  • 20. In Closing ● ● There's quite a bit about classes which we have not covered. This will be an ongoing series so keep an eye out for more to come. ● Thank you for attending. ● Twitter: @terminalbreaker