Ruby OOP: Objects over Classes

50 %
50 %
Information about Ruby OOP: Objects over Classes

Published on March 23, 2010

Author: amanking



A talk presented in RubyConf India 2010 at Bangalore, India. It revisits the role of objects and classes in Ruby OOP, and encourages programmers to discover a new approach to OOP.

Ruby OOP: Objects over Classes Aman King RubyConf India 2010

What is OOP?

What is a class?

What is an object?

But before the serious stuff …

Detouring through a comic book universe … Image copyrighted by respective owners Source:

Coming back …

What is an object?

Something that takes birth …

exhibits some behavior …

interacts with other objects …

and finally dies off or is simply forgotten …

all in an effort to solve a problem.

What is a class?

A container for related behavior …

that a new object can start off with.

A class itself is an object …

used to create other objects.

When creating a new object, a class calls the object’s private initialize method.

Typically a class is named …

referenced via a global constant variable.

A class object can have singleton methods added to it.

These singleton methods can be invoked wherever the class object is accessible …

aka “class-level methods”.

Why use classes?

Some possible reasons

An object remembers the class used to create it …

explicit type checking using kind_of? …

implicit type checking using case syntax …

implicit type checking using rescue syntax.

A class can build on other classes: inheritance.

A class can share state across multiple objects: @@class_variables.

Some good reasons

A named container of behavior can have more behavior added to it.

Any added behavior becomes part of all objects created by that class.

A class can represent a common pattern of initialization.

Classes improve readability and maintainability.

What a class is not?

The fundamental building block of an application.

A strong data type.

An enforcement of contract or limitations on how objects can behave.

Ruby’s object focus

Classes are objects.

No static method-lookup tables: chain of ancestors.

Singleton methods.

Private access modifier is object-level.

Duck typing.

Finding hints in the real world …

Objects over classes: Consequences

Classes and hierarchies no longer limit you.

Think through the usage of class-level methods and variables: globals?

Understanding meta-programming is easier.

Effective and confident use of meta-programming.

Final words

Objects are first-class citizens.

Classes are useful but secondary.

Thank you

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

OOP in Ruby - ZetCode, tutorials for programmers

Object-oriented programming in Ruby. ... In a OOP program, we create objects. ... Over the years users are accustomed to using specific methods and ...
Read more

oop - Why Object.class == Class in Ruby? - Stack Overflow

Why Object.class == Class in Ruby? ... two parallel hierarchies of classes and ... package ruby objects into an array and iterate over them in a ...
Read more

Ruby as a "pure" object oriented language ...

Ruby as a “pure” object oriented language — inconsistency with Ruby ... or socket classes. ... as in OOP) for methods that are used all over ...
Read more

Object-oriented programming - Wikipedia, the free encyclopedia

Object-oriented programming (OOP) ... classes and objects can be composed using ... and libraries such as Java Data Objects and Ruby on Rails ...
Read more

Object-Oriented Concepts | The Bastards Book of Ruby

... modeled in code by "objects." In OOP, ... basic code to set up classes in Ruby. ... and paste it over to the Actress class. What OOP concept did we ...
Read more

Sessions at RubyConf India 2010 about Object Oriented ...

Ruby OOP - Objects over Classes. by Aman King. Asked to design an object-oriented solution to a problem, ... A language like Ruby, however, ...
Read more

Learn Ruby the Hard Way - Read for Free

... (OOP) is just plain weird ... Ruby also has another construct that ... this should only serve as a way for you to bridge over to understanding classes ...
Read more

Ruby - Object Oriented - Tutorialspoint

Object Oriented Ruby ... A beginner's tutorial containing complete knowledge of Ruby Syntax Syntax, Classes ... Ruby does not apply any access control over ...
Read more

Skill Pages - OOP |

... meaning that objects are instances of classes, ... OOP Popularity Over Time. ... Classes, Interfaces and OOP.
Read more