Use when working with Ruby's object-oriented programming features including classes, modules, inheritance, mixins, and method visibility.
View on GitHubTheBushidoCollective/han
jutsu-ruby
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-ruby/skills/ruby-object-oriented-programming/SKILL.md -a claude-code --skill ruby-oopInstallation paths:
.claude/skills/ruby-oop/# Ruby Object-Oriented Programming
Master Ruby's elegant object-oriented programming features. Ruby is a pure object-oriented language where everything is an object.
## Class Definition
### Basic Class Structure
```ruby
class Person
# Class variable (shared across all instances)
@@count = 0
# Constant
MAX_AGE = 150
# Class method
def self.count
@@count
end
# Constructor
def initialize(name, age)
@name = name # Instance variable
@age = age
@@count += 1
end
# Instance method
def introduce
"Hi, I'm #{@name} and I'm #{@age} years old"
end
# Attribute accessors (getter and setter)
attr_accessor :name
attr_reader :age # Read-only
attr_writer :email # Write-only
end
person = Person.new("Alice", 30)
puts person.introduce
person.name = "Alicia"
```
### Method Visibility
```ruby
class BankAccount
def initialize(balance)
@balance = balance
end
# Public methods (default)
def deposit(amount)
@balance += amount
log_transaction(:deposit, amount)
end
def balance
format_currency(@balance)
end
# Protected methods - callable by instances of same class/subclass
protected
def log_transaction(type, amount)
puts "[#{type}] #{amount}"
end
# Private methods - only callable within this instance
private
def format_currency(amount)
"$#{amount}"
end
end
```
## Inheritance
### Single Inheritance
```ruby
class Animal
def initialize(name)
@name = name
end
def speak
"Some sound"
end
end
class Dog < Animal
def speak
"Woof! My name is #{@name}"
end
# Call parent method with super
def introduce
super # Calls parent's speak method
puts "I'm a dog"
end
end
dog = Dog.new("Buddy")
puts dog.speak
```
### Method Override and Super
```ruby
class Vehicle
def initialize(brand)
@brand = brand
end
def start_engine
puts "Engine starting..."
end
end
class Car < Vehicle
def initialize(brand, model)
super(brand) Issues Found: