Ruby Tutorial
Ruby CGI
Ruby Advanced
Object-oriented programming is a programming paradigm that is based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).
Ruby is a pure object-oriented language, meaning everything in Ruby is an object, even data types like integers, booleans, and "nil".
Here are the basic concepts of OOP in Ruby:
class Person def initialize(name, age) @name = name @age = age end end
person = Person.new("John", 30)
class Person def initialize(name, age) @name = name @age = age end def name @name end def age @age end end
class Person def initialize(name, age) @name = name @age = age end def introduce "Hello, my name is #{@name} and I am #{@age} years old." end end
class Employee < Person def initialize(name, age, job_title) super(name, age) @job_title = job_title end def introduce "Hello, my name is #{@name}, I am #{@age} years old, and I am a #{@job_title}." end end
class Person def initialize(name, age) @name = name @age = age end def increase_age @age += 1 end def age @age end end
class Animal def make_sound "..." end end class Cat < Animal def make_sound "Meow" end end class Dog < Animal def make_sound "Woof" end end
That's a very basic introduction to OOP in Ruby. Each of these topics could be expanded on significantly, but this should give you a good starting point.