Skip to content

louman/loser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

loser

Loser adds error behavior to you ruby class allowing you to easily handle failures.

Installation

gem install loser

Usage

Include Loser module to you ruby class with:

class Car

  include Loser
  
  def initialize
    @fuel = 0
  end
  
  def start
    if has_fuel?
      true
    else
      fail('Low fuel')
    end
  end
  
  def refuel(amount)
    @fuel += amount
  end
  
  private
  
  def has_fuel?
    @fuel > 0
  end
end

car = Car.new
car.start           # => false
car.valid?          # => false
car.errors          # => ["Low fuel"]
car.errors_full     # => "Low fuel"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages