ruby
ruby
ruby
Ruby as a Bash replacement: Writing powerful system scripts in Ruby
Ruby can replace Bash for system scripts that outgrow a few lines: real error handling, readable syntax, easy testing. Examples of bulk folder compression, process management, file operations, making scripts executable, and when Bash is still the better pick.
ruby
Creating predictable randomness in Ruby: The magic of seeds
Reproducible randomness in Ruby sounds like a contradiction, but seeds make it easy: how pseudo-random generators work, fixed seeds for tests, debugging, and procedural generation, creative ways to pick seeds, and the pitfalls that quietly break determinism.
Latest
What is the difference between Fixtures and Factories in Ruby on Rails tests?
Fixtures or factories for Rails tests? How each approach works: static YAML data Rails loads before every run versus FactoryBot objects built on demand, with examples and clear guidance on when speed favors fixtures and flexibility favors factories.
Event Sourcing in practice: Lessons from the trenches
Event Sourcing can be introduced to legacy systems incrementally, no big rewrite required. Lessons from production: the migration event technique, upcasting old events, right-sizing aggregates, stream lifecycles, and payoffs in audits, analytics, and debugging.
How to create multi trait inside trait in FactoryBot
FactoryBot traits can nest other traits, letting you compose reusable test fixtures instead of copying attribute blocks. A quick refresher on traits, then the traitception pattern: defining traits inside traits and combining them for cleaner Rails test setup.
Embracing Hexagonal Architecture in Ruby
Hexagonal Architecture separates your business logic from databases, UIs, and external services using ports and adapters. What the pattern really means, a practical Ruby implementation, when it pays off, and the common problems teams hit when adopting it.
What is ENVIRONMENT in rake task?
The :environment dependency in Rake tasks is what loads your Rails app, models, and database connections. What task my_task: :environment actually does behind the scenes, how the Rake dependency syntax works, and why skipping it breaks your custom tasks.
OJ is not as safe as you think for your JSON
OJ speeds up JSON in Ruby, but Oj.mimic_JSON silently drops the script_safe option, opening the door to XSS, and adds time precision quirks. What its monkey patching really changes, the stability risks, and best practices for using OJ without surprises.
What is params.expect and how to use it in Rails 8?
params.expect in Rails 8 replaces require/permit and fixes a real weakness: crafted params like ?user=string used to raise NoMethodError and 500 errors. How the new syntax works, how it handles arrays with precision, and how to migrate your controllers.
How to write custom RSpec matchers in your Ruby on Rails app
Custom RSpec matchers turn repetitive assertions into readable, reusable specs. Step by step: define a matcher with RSpec::Matchers.define, add clear failure messages, build flexible matchers that take arguments, and wire them into your Rails test suite.
What's new in Ruby 3.4
Ruby 3.4 adds the new 'it' block parameter that makes .then chains and maps cleaner than numbered parameters, chilled strings as a step toward immutability, and enhanced Range operations. What each change looks like in practice, with before and after code.
How to add rate limiting in Ruby on Rails 8
Rate limiting in Rails 8 is built in: the rate_limit method declares limits per controller and action, like 3 requests per 2 seconds on create. How to combine short and long windows, protect unsafe actions, and practical suggestions for sensible limits.
Mastering database enums in Rails with Postgres - Guide
Database enums in PostgreSQL give Rails apps type safety, implicit ordering, and faster queries than string columns. Single-value enums with validation, multi-select enum arrays, dynamic enum management, and the migrations that wire it all together.
How to run Rails console in safe sandbox mode?
Rails console sandbox mode wraps every database operation in a transaction and rolls it all back on exit, so you can experiment safely. How to launch it, plus the traps: database locking, non-rollbackable operations, and why production use still needs care.
Dealing with legacy code that uses different method naming conventions
Legacy services with mismatched method names (validate, execute!, run!) can be unified with Ruby method objects. How to build one dispatcher that calls the right method on each class, why it beats conditionals, and what it does for readability.
How to get table size in PostgreSQL database?
PostgreSQL table size is more than the data: pg_table_size, pg_indexes_size, and pg_total_relation_size each measure different things. One ready SQL query lists every table with data, index, and total size, sorted by the biggest disk consumers first.
What is Frugal architecture?
Frugal Architecture is Werner Vogels' framework for cost-conscious system design: three pillars (Design, Measure, Optimize) and seven laws, from treating cost as a non-functional requirement to continuous optimization, explained with practical examples.
The Truth About Password Security: Beyond Special Characters
Password security depends on entropy, not special characters. The math behind entropy = N * log2(R), why length beats complexity rules, why database breaches (not login guessing) are the real threat, and implementation tips for saner password policies.
How to listen to Rails events
ActiveSupport::Notifications lets you listen to Rails events like transaction.active_record without extra gems. How the instrumentation API works, subscribing to built-in Rails events, and publishing your own custom events for better observability.
Adding colors to your Ruby scripts and console logs: A Developer's guide
Colored terminal output in Ruby takes a few lines: extend String with ANSI escape methods like red, green, and bold, add colorized logging to the Rails logger, or reach for a gem when you need more. Copy-paste snippets for scripts and console logs.
Mastering Ruby's argument handling: positional, keyword, and the magic of three dots
Ruby argument handling explained: positional arguments with *args, keyword arguments with **kwargs, and the three-dot syntax from Ruby 2.7 that forwards everything at once. Code examples for each, plus guidance on when each style keeps methods readable.
Streamlining Rails controllers with custom filters
Rails controllers bloated with subscription checks? Extract that logic into custom filter classes: a before_action that delegates to a dedicated object, giving cleaner controllers, clearer error messages, easier testing, and a pattern you can expand.