DEV Community

Cover image for Ruby PORO Explained: How Plain Old Ruby Objects Make Your Code Better
Zil Norvilis
Zil Norvilis

Posted on

Ruby PORO Explained: How Plain Old Ruby Objects Make Your Code Better

A PORO in Ruby stands for Plain Old Ruby Object.
It simply means a regular Ruby class that isn’t tied to Rails-specific inheritance, modules, or frameworks.

🚀 What makes something a PORO?

A class is a PORO if:

  • It inherits from nothing except Object (implicitly).
  • It does not depend on Rails magic — no ActiveRecord::Base, no ApplicationController, no ActiveJob, etc.
  • It’s just plain Ruby logic.

👍 Why use POROs?

Developers use POROs in Rails apps to:

  • Encapsulate business logic outside models/controllers.
  • Keep code clean and testable.
  • Avoid bloated models (the “fat model” problem).
  • Create service objects, value objects, form objects, presenters, etc.

🧱 Example of a PORO

class PriceCalculator
  def initialize(base_price, tax_rate)
    @base_price = base_price
    @tax_rate = tax_rate
  end

  def total
    @base_price + (@base_price * @tax_rate)
  end
end

calc = PriceCalculator.new(100, 0.21)
puts calc.total # => 121.0
Enter fullscreen mode Exit fullscreen mode

This class:

  • Doesn’t rely on Rails.
  • Doesn’t inherit from any Rails class.
  • Is just Ruby.

🤔 Example inside Rails

You might put something like this in app/services/my_service.rb:

class MyService
  def call
    # pure Ruby logic
  end
end
Enter fullscreen mode Exit fullscreen mode

Rails doesn’t care — it loads the file, but everything inside is plain Ruby.

Top comments (0)