SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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.
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.

Weitere ähnliche Inhalte

Was ist angesagt?

On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
Antonelo Schoepf
 
The ruby programming language
The ruby programming languageThe ruby programming language
The ruby programming language
praveen0202
 
Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclass
xds2000
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
myuser
 
Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developers
Max Titov
 
Lets talk-about-js
Lets talk-about-jsLets talk-about-js
Lets talk-about-js
srnftw
 
Java classes and objects interview questions
Java classes and objects interview questionsJava classes and objects interview questions
Java classes and objects interview questions
Dhivyashree Selvarajtnkpm
 

Was ist angesagt? (20)

Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
05 ruby classes
05 ruby classes05 ruby classes
05 ruby classes
 
Object oriented programming in JavaScript
Object oriented programming in JavaScriptObject oriented programming in JavaScript
Object oriented programming in JavaScript
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
 
Introduction to Object Oriented Javascript
Introduction to Object Oriented JavascriptIntroduction to Object Oriented Javascript
Introduction to Object Oriented Javascript
 
The ruby programming language
The ruby programming languageThe ruby programming language
The ruby programming language
 
Ruby's metaclass
Ruby's metaclassRuby's metaclass
Ruby's metaclass
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developers
 
JavaScript - Zero To Hero - Class 1
JavaScript - Zero To Hero - Class 1JavaScript - Zero To Hero - Class 1
JavaScript - Zero To Hero - Class 1
 
Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developers
 
Lets talk-about-js
Lets talk-about-jsLets talk-about-js
Lets talk-about-js
 
Java object
Java objectJava object
Java object
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
Java classes and objects interview questions
Java classes and objects interview questionsJava classes and objects interview questions
Java classes and objects interview questions
 
Java scriptforjavadev part1
Java scriptforjavadev part1Java scriptforjavadev part1
Java scriptforjavadev part1
 
Lec08 constructors
Lec08   constructorsLec08   constructors
Lec08 constructors
 
String interpolation
String interpolationString interpolation
String interpolation
 

Ähnlich wie Intro Ruby Classes Part I

Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew
ThoughtWorks
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
dannygriff1
 

Ähnlich wie Intro Ruby Classes Part I (20)

Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew
 
Ruby OOP: Objects over Classes
Ruby OOP: Objects over ClassesRuby OOP: Objects over Classes
Ruby OOP: Objects over Classes
 
Ruby Interview Questions
Ruby Interview QuestionsRuby Interview Questions
Ruby Interview Questions
 
The Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael MaganaThe Ruby Object Model by Rafael Magana
The Ruby Object Model by Rafael Magana
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for ruby
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Me, my self and IPython
Me, my self and IPythonMe, my self and IPython
Me, my self and IPython
 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
OOPS ABAP.docx
OOPS ABAP.docxOOPS ABAP.docx
OOPS ABAP.docx
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

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.
  • 15.
  • 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