claudegoodies
Command

model

From davila7

Create Ruby classes and models with proper structure and best practices.

Install

/model

Facts

Status
Actively maintained
Last commit

Source preview

The instructions Claude Code reads when this command runs.

# Ruby Model Generator

Create Ruby classes and models with proper structure and best practices.

## Purpose

This command helps you quickly create Ruby model classes with proper initialization, attributes, and methods following Ruby conventions.

## Usage

```
/model
```

## What this command does

1. **Creates model classes** with proper initialization methods
2. **Adds attribute accessors** and instance variables
3. **Includes validation methods** and error handling
4. **Follows Ruby conventions** and best practices
5. **Generates related test files** when applicable

## Example Output

```ruby
# app/models/user.rb
class User
  attr_accessor :name, :email, :age
  attr_reader :id, :created_at
  
  def initialize(attributes = {})
    @id = attributes[:id] || generate_id
    @name = attributes[:name]
    @email = attributes[:email]
    @age = attributes[:age]
    @created_at = Time.now
    @errors = []
  end
  
  def valid?
    @errors.clear
    validate_presence_of_name
    validate_email_format
    validate_age_range
    @errors.empty?
  end
  
  def errors
    @errors.dup
  end
  
  def save
    return false unless valid?
    
    # Persist logic here
    true
  end
  
  def to_h
    {
      id: @id,
      name: @name,
      email: @email,
      age: @age,
      created_at: @created_at
    }
  end
  
  def to_json(*args)
    JSON.generate(to_h, *args)
  end
  
  private
  
 
View full source on GitHub →

Other slash commands