Ruby Naming Conventions
Fast recall
Quick revision
Core answer
snake_case for local variables, methods, and files; CamelCase for class and module constants; and UPPER_SNAKE_CASE for ordinary constants. A method ending in ? reads as a predicate, = defines assignment-style syntax, and ! normally marks a more dangerous counterpart—not a language guarantee that mutation occurs. Names should describe domain meaning and follow framework path conventions so readers and autoloaders can predict where behaviour lives.Whether you know snake_case for vars/methods, CamelCase for classes, SCREAMING for constants, and ?/! suffixes for booleans/mutators.
Using camelCase for methods (Java style) or sprinkling ! on every method (it means mutate/danger, not emphasis).
snake_case (vars/methods), CamelCase (classes), SCREAMING_SNAKE (constants), ? for booleans, ! for mutators. Files match the class. RuboCop enforces it.
Interview-ready guide
Interview answer
Ruby's naming conventions make code predictable even though many identifier forms are technically legal. Methods, local variables, and files normally use snake_case; classes and modules use CamelCase; constants commonly use UPPER_SNAKE_CASE.
Method punctuation communicates part of the contract. A name ending in ?, such as empty?, reads as a question and should return a truthy or falsy result. A method ending in = supports assignment syntax, so user.name = 'Ada' calls name=.
A bang suffix conventionally marks a more dangerous version relative to a non-bang method. String#upcase! may modify its receiver while upcase returns a new string, but Ruby does not enforce this pattern and not every mutating method has !. The pair's documented behaviour is authoritative.
For example, PaymentReport belongs in payment_report.rb, and Rails may expect Admin::PaymentReportsController under admin/payment_reports_controller.rb. Matching constant and file names supports normal autoloading and quick navigation.
The goal is semantic clarity, not abbreviating everything. eligible_for_refund? reveals more than check?, and consistent names reduce the explanations future readers need.
Ruby Naming Conventions
Direct Answer
Ruby convention uses snake_case for local variables, methods, and files; CamelCase for class and module constants; and UPPER_SNAKE_CASE for ordinary constants. A method ending in ? reads as a predicate, = defines assignment-style syntax, and ! normally marks a more dangerous counterpart—not a language guarantee that mutation occurs. Names should describe domain meaning and follow framework path conventions so readers and autoloaders can predict where behaviour lives.
Deep Dive & Architecture
Ruby's parser distinguishes constants by an initial uppercase letter and recognises method suffixes such as ?, !, and =. Community conventions build readable promises on top of those legal forms, allowing a call site to suggest whether it asks a question, changes state, or assigns an attribute.
The bang convention is comparative. It says 'pay attention to how this differs from the ordinary form', often because it mutates or raises. A lone method does not become well designed by adding !, and callers still need its actual return and failure contract.
File naming becomes executable structure in autoloaded applications. A snake-case path maps to a constant path, so a rename may require changing both the file and constant. Case-insensitive development filesystems can hide a mismatch that later fails on Linux.
Domain vocabulary matters more than mechanical style. A precise noun for an object and a verb for an operation help classes divide responsibilities and methods reveal effects. Consistency makes unfamiliar code navigable; specificity makes it understandable.
Code Example
MAX_RETRIES = 3
class PaymentReport
attr_writer :status
def initialize(total)
@total = total
@status = :draft
end
def ready?
@total.positive? && @status == :approved
end
end
report = PaymentReport.new(50)
report.status = :approved # calls status=
report.ready? # => true
Common Mistakes & Pitfalls
Using camelCase for methods (Java style) or sprinkling ! on every method (it means mutate/danger, not emphasis).
Check your understanding
Answer these without looking back at the article.
- Does a bang method always mutate its receiver?
- What should a predicate method ending in `?` return?
- Why can Ruby file naming affect Rails autoloading?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.