Ruby Development Protocol
Version: 1.1.0
Author: Sashité
Published: May 5, 2025
License: MIT License
1. Core Principles
- Code must follow functional programming principles.
- Object state mutation is prohibited.
- Pure functions must be preferred wherever possible.
- Threads are prohibited.
- One file per constant, per class, per module.
- Strict methods must be preferred over lax methods (e.g., use
#fetch
instead of #[]
on collections).
2. Object Structure
- Instance variables must only be assigned in
initialize
.
- All objects must be frozen after initialization via
freeze
.
- Use
attr_reader
; attr_writer
and attr_accessor
are prohibited.
- Methods mutating internal collections must end with
!
.
- Prefer immutable value semantics.
Explicit Internal State Changes
- Internal collections (e.g., arrays, hashes) may be mutated post-initialization.
- Mutating methods must end with
!
and be documented as having side effects.
- Reassignment of instance variables after initialization is prohibited.
3. Parameters and Arguments
- Use keyword arguments instead of hash parameters.
- Use splat (
*args
) for ordered arguments instead of arrays.
- Use double splat (
**kwargs
) for named arguments instead of hashes.
- Optional parameters must have explicit default values.
- All arguments must be validated at method entry.
Examples:
# Recommended:
def add(*pieces)
# ...
end
def load(name:, **options)
# ...
end
4. Import/Export Protocol (from_params
/ to_params
)
Interface
self.from_params(**params) → instance
to_params() → Hash
Principles
from_params(**obj.to_params)
must reconstruct an equivalent object.
to_params
reflects current state.
- Output must include all reconstructable data.
- Original input is not preserved — only state.
Constraints
from_params
must be pure.
- Objects with identical
to_params
are logically equivalent.
5. References and Constants
- Use
::
for top-level constants (e.g., ::String
).
- Declare dependencies explicitly.
- Avoid type mixins. Use only simple types.
6. Method Conventions
!
methods perform side effects and return nil
.
?
methods return booleans.
- Return types must be consistent within method families.
- Identical method names across classes must return the same type.
- Do not prefix booleans with
is_
or has_
.
- Methods must return a single type (or
nil
).
7. Naming Conventions
- Names must be explicit and descriptive.
- Arrays must have names ending in
s
.
- All names must be in technical English.
- Default method name should be
call
.
- Constants use CamelCase.
8. Error Handling and Validation
- Validate all inputs before use.
- Raise explicit exceptions on anomalies.
- Document expected types in comments.
- Follow fail-fast design.
- Clearly document exceptions.
9. Security and Safety
- External system calls must be isolated in dedicated methods or classes.
10. Documentation
- Document intention, not implementation.
- Specify parameter and return types.
- Document all side effects.
- Write all documentation in technical English.
11. Type Coercion
Prefer Kernel methods over object methods for type conversion:
- Use
String(x)
, Array(x)
, Integer(x)
instead of x.to_s
, x.to_a
, x.to_i
, etc.
- These conversions are safer, more explicit, and fail predictably on invalid input.
Example:
# Recommended:
def format_name(input)
name = String(input) # raises if input is invalid
# ...
end
Copyright © 2011–2025 Sashité