Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Object-oriented
programing in Ruby
Ngoc Nguyen
Overview
❖ Introduction
❖ Class
❖ Object
❖ Inheritance
❖ Super method
OOP in Ruby
❖ Uses Object and their interactions to design application
and computer programs
❖ Basic Concepts
➢ Abstractio...
Basic Concepts
❖ Abstraction
➢ simplifying complex reality by modeling class appropriate to the
problem.
❖ Polymorphism
➢ ...
Basic Concepts
● Encapsulation
o hides the implementation of a class from other object
● Inheritance
o a way to form new c...
Class
❖ is used to specify the form of an object
❖ combines data representation and methods for
manipulating that data int...
Object
❖ are basic building blocks of OOP program
❖ combination of data and methods
❖ communicate together throught method...
Object
❖ Two steps in creating object
➢ define a class
➢ run a instance of that particular class
The constructor
❖ special kind of method
❖ automatically called when object is created
❖ initiate the state of an object
❖...
The Constructor
❖ object’s attributes - instance variables or member fields
➢ data items into that object
❖ `allocate` met...
Constructor Overloading
❖ has no constructor overloading
➢ object is created with default parameter values
Methods
❖ are functions defined inside the body of class
❖ used to perform operations with object’s attributes
Methods
❖ instance methods
➢ the method that the object contains
❖ class methods
➢ the method that created by self class
➢...
Accessor & Setter methods
❖ to make variables available from outsite class
❖ define variables (set values)
Inheritance
❖ newly formed classed are called derived classes
❖ the classes that we derive from are called base classes
❖ ...
Inheritance
❖ use `<` operator to create inheritance relations
❖ `super` method to call parent function
❖ `ancestors` meth...
The super method
❖ call a method of the same name in the parent’s class
❖ super
➢ passed all arguments to parent’s classes...
References
❖ Object oriented Ruby
➢ http://www.tutorialspoint.com/ruby/ruby_object_oriented.htm
❖ Object-oriented programm...
Upcoming SlideShare
Loading in …5
×

Object-oriented in ruby

311 views

Published on

Object-Oriented Programing in Ruby

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Object-oriented in ruby

  1. 1. Object-oriented programing in Ruby Ngoc Nguyen
  2. 2. Overview ❖ Introduction ❖ Class ❖ Object ❖ Inheritance ❖ Super method
  3. 3. OOP in Ruby ❖ Uses Object and their interactions to design application and computer programs ❖ Basic Concepts ➢ Abstraction ➢ Polymorphism ➢ Encapsulation ➢ Inheritance
  4. 4. Basic Concepts ❖ Abstraction ➢ simplifying complex reality by modeling class appropriate to the problem. ❖ Polymorphism ➢ process of using a operator or function in different ways for different data input.
  5. 5. Basic Concepts ● Encapsulation o hides the implementation of a class from other object ● Inheritance o a way to form new classes using classes that have already been define
  6. 6. Class ❖ is used to specify the form of an object ❖ combines data representation and methods for manipulating that data into one packet ❖ data and methods in class are members of class
  7. 7. Object ❖ are basic building blocks of OOP program ❖ combination of data and methods ❖ communicate together throught methods ❖ can receive, send message, process data
  8. 8. Object ❖ Two steps in creating object ➢ define a class ➢ run a instance of that particular class
  9. 9. The constructor ❖ special kind of method ❖ automatically called when object is created ❖ initiate the state of an object ❖ called is `initialize`
  10. 10. The Constructor ❖ object’s attributes - instance variables or member fields ➢ data items into that object ❖ `allocate` method ➢ create object without constructor
  11. 11. Constructor Overloading ❖ has no constructor overloading ➢ object is created with default parameter values
  12. 12. Methods ❖ are functions defined inside the body of class ❖ used to perform operations with object’s attributes
  13. 13. Methods ❖ instance methods ➢ the method that the object contains ❖ class methods ➢ the method that created by self class ➢ define: “self.method_name”
  14. 14. Accessor & Setter methods ❖ to make variables available from outsite class ❖ define variables (set values)
  15. 15. Inheritance ❖ newly formed classed are called derived classes ❖ the classes that we derive from are called base classes ❖ the devired classes override or extend the functionality of base classes
  16. 16. Inheritance ❖ use `<` operator to create inheritance relations ❖ `super` method to call parent function ❖ `ancestors` method to show lists of ancestors
  17. 17. The super method ❖ call a method of the same name in the parent’s class ❖ super ➢ passed all arguments to parent’s classes ❖ super() ➢ no arguments passed to perent’s classes
  18. 18. References ❖ Object oriented Ruby ➢ http://www.tutorialspoint.com/ruby/ruby_object_oriented.htm ❖ Object-oriented programming in Ruby ➢ http://zetcode.com/lang/rubytutorial/oop/

×