Who am I
●

Juan Leal
–

Rubyist and Rails Developer since 2007

–

Worked at Equifax and Pragmatic Programmers

–

Curren...
What We'll Cover
●

A review of Classes and Objects

●

Some basics of classes in Ruby

●

●

Some background info regardi...
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 me...
Classes vs Objects
●
●

●

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

Class
...
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 ha...
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 Cl...
So...
an instance of

class

Class
Class is an object.
Remember in Ruby everything is an object.
Class is an instance of c...
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...
In Closing
●

●

There's quite a bit about classes which we have
not covered.
This will be an ongoing series so keep an ey...
The End.
Intro Ruby Classes Part I
Upcoming SlideShare
Loading in …5
×

Intro Ruby Classes Part I

1,097 views

Published on

An intro into Ruby classes.

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,097
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Intro Ruby Classes Part I

  1. 1. Who am I ● Juan Leal – Rubyist and Rails Developer since 2007 – Worked at Equifax and Pragmatic Programmers – Currently employed at Hiplogiq
  2. 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. 3. A review of Classes and Objects
  4. 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. 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. 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. 7. Classes in Ruby, some basics
  8. 8. Defining a class Here we define a class and a method.
  9. 9. Inheritance Here the class Bar inherits from class Foo.
  10. 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. 11. Ruby classes, some background information.
  12. 12. General points ● In Ruby everything is object. ● Objects are instances of a class. ● Simple right?
  13. 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. 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. 15. 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.
  16. 16. Using class Class.
  17. 17. The class Class Let's take a look at what we can do with Class. We can define classes. We can do inheritance.
  18. 18. 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.
  19. 19. 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
  20. 20. The End.

×