SimpleCar

A minimal Ruby class that represents a car and its running state.

What it provides

  • Auto-generated UUID id (or custom id)
  • Car metadata: make, model, year
  • Engine state control: start, stop, is_running
  • String representation via to_s

Requirements

  • Ruby 3.1+

Import

Use one of the following approaches:

require "simple_car"

or, when loading directly from the repository:

require_relative "lib/simple_car"

Quick Start

require "simple_car"

car = SimpleCar.new("Toyota", "Corolla", 2020)

puts car.id          # generated UUID
puts car.make        # "Toyota"
puts car.model       # "Corolla"
puts car.year        # 2020
puts car.wheels      # 4
puts car.is_running  # false

car.start
puts car.is_running  # true

car.stop
puts car.is_running  # false

puts car.to_s
# => "<id> 2020 Toyota Corolla (SimpleCar) Not Running"

Custom ID

car = SimpleCar.new("Ford", "Mustang", 1968, "car-001")
puts car.id # "car-001"

If id is nil or empty, SimpleCar generates a UUID automatically.

API Reference

  • SimpleCar.new(make, model, year, id = nil)
  • id -> String
  • make -> String
  • model -> String
  • year -> Integer (or any value passed in)
  • wheels -> 4
  • is_running -> true / false
  • start -> sets running state to true
  • stop -> sets running state to false
  • to_s -> "<id> <year> <make> <model> (SimpleCar) <Running|Not Running>"