rails-stylelisted
Install: claude install-skill mickzijdel/rails-toolkit
# Rails Code Style
## 1. Method Ordering
Order methods in classes: class methods first, then public methods (`initialize` at the top), then private methods.
```ruby
class SomeClass
# 1. Class methods first
class << self
def deliver_all_later
DeliverAllJob.perform_later
end
end
# 2. Public methods (initialize first if present)
def initialize(user)
@user = user
end
def deliver
# ...
end
# 3. Private methods
private
def deliverable?
# ...
end
end
```
---
## 2. Invocation Order
Within each visibility section, order methods vertically by invocation: callers before the methods they call.
```ruby
class SomeClass
def some_method
method_1
method_2
end
private
def method_1
method_1_1
method_1_2
end
def method_1_1
# ...
end
def method_1_2
# ...
end
def method_2
# ...
end
end
```
---
## 3. Conditional Returns
Prefer expanded conditionals over guard clauses.
```ruby
# Bad
def todos_for_new_group
ids = params.require(:todolist)[:todo_ids]
return [] unless ids
@bucket.recordings.todos.find(ids.split(","))
end
# Good
def todos_for_new_group
if ids = params.require(:todolist)[:todo_ids]
@bucket.recordings.todos.find(ids.split(","))
else
[]
end
end
```
**Exception:** a guard clause is acceptable when the return is right at the beginning of the method *and* the main body is non-trivial:
```ruby
def after_recorded_as_commit(r