CLI tool for mirroring GitHub repos to Tangled.org
Something went wrong. Try again.
994 B
Markdown
at dev
Ruby Best Practices #
Code Style #
- Follow Ruby Style Guide (use RuboCop)
- Use 2 spaces for indentation
- Prefer symbols over strings for hash keys
- Use
snake_casefor methods and variables
# GOOD: Idiomatic Ruby
class UserService
def initialize(repository)
@repository = repository
end
def find_user(id)
@repository.find(id)
rescue ActiveRecord::RecordNotFound
nil
end
end
# BAD: Non-idiomatic
class UserService
def initialize(repository)
@repository = repository
end
def findUser(id) # Wrong naming
begin
@repository.find(id)
rescue
return nil
end
end
end
Error Handling #
- Use specific exception classes
- Don't rescue
Exception(too broad) - Use
ensurefor cleanup
Security #
- Use parameterized queries (ActiveRecord does this by default)
- Sanitize user input in views (Rails does this by default)
- Never use
evalorsendwith user input - Use
strong_parametersin Rails controllers