Alternative to #to_a and Array(...)

Turning arbitrary values into arrays can trigger to_a deprecation warnings and inconsistent nil behavior. Array.wrap or listify provide a safer conversion.

Stub methods on any instance of a class in Rspec 1 and Rspec 2

Stub a method on every instance of a class to control behavior in tests, using stub_any_instance, any_instance.stub, or allow_any_instance_of.

Understanding SQL compatibility modes in MySQL and MariaDB

SQL mode mismatches can break apps after MySQL or MariaDB upgrades by changing strictness, grouping rules, and allowed values.

How to change the order of nested forms being rendered (especially blank forms)

Blank nested forms usually render last; reordering the one-to-many association changes their position and can move the empty form to the top.

Thread-safe collections in Ruby

Shared data in threaded Ruby code needs protection or immutability; concurrent-ruby offers thread-safe Array and Hash, and Hamster uses immutable collections.

Email validation regex

Ruby email checks can be simplified with URI::MailTo::EMAIL_REGEXP, while stricter web forms often need a top-level domain and looser validation may use Devise's pattern.

Ruby 2.3.0 has a safe navigation operator

Ruby 2.3.0 adds &. for nil-safe method calls, preventing NoMethodError when receivers can be absent while leaving false behavior unchanged.

How to make Rational#to_s return strings without denominator 1 again

Ruby 1.9+ renders integer-valued Rational objects as 2/1, which can leak into views and date calculations. A small override restores the Ruby 1.8-style integer string output.

Careful with '||=' - it's not 'memoize'

||= does not memoize nil values, so expensive lookups or database queries may run repeatedly when the result is absent. Use defined-instance-variable caching when nil must be cached.

Bash: How to use colors in your tail output

Coloring tail output makes log levels easier to scan, and ANSI escape codes in sed can highlight INFO and FATAL lines in different colors.

There is no real performance difference between "def" and "define_method"

def and define_method have no meaningful performance gap in typical Ruby code; only very short methods show a small difference, while closures can affect garbage collection.

Understanding database cleaning strategies in tests

Test databases need cleanup between examples to keep state isolated; transactions are fastest, while browser-driven tests or MyISAM tables require deletion or truncation.

Things to consider when using Travis CI

Fragile CI builds on Travis often fail with Ruby 1.8.7, incompatible Rubygems, or debugger gems in the test bundle.

Fix: esbuild assets are missing after capistrano deploy

esbuild output can disappear after a Capistrano deploy when app/builds is not committed, leaving public/assets incomplete. Sprockets may ignore files in unknown paths.

Unpoly 2: Don't try to download files through AJAX requests

AJAX downloads fail because browsers try to render files instead of saving them. Exclude download links from Unpoly link handling and use Content-Disposition: attachment or download.

Limiting CPU and memory resources of Paperclip convert jobs

Paperclip image conversions can spike CPU and memory during heavy uploads. ImageMagick resource limits and nice help reduce contention on Unix systems.

PostgreSQL: Ordering, NULLs, and indexes

PostgreSQL sorting puts NULL values first or last depending on direction, and matching index order is needed for efficient multi-column queries.

Maximum representable value for a Ruby Time object

32-bit Ruby Time values stop at 2038-01-19 03:14:07 UTC; later timestamps raise ArgumentError. DateTime can store later dates but differs from Time and is slower.

ActiveModel::Errors inherits from hash and behaves unexpectedly

ActiveModel::Errors looks like a Hash but iterates arrays as separate pairs, which can break custom handling of multiple validation messages.

Using Bumbler to Reduce Runtime Dependencies - The Lean Software Boutique

bumbler identifies slow-loading Ruby gems that inflate startup time and runtime dependencies.

Delete all MySQL records while keeping the database schema

Clear MySQL data without dropping tables, useful after bad migrations or frozen tests. DatabaseCleaner truncation keeps the schema intact and can be wrapped in a Rake task.

randym/axlsx ยท GitHub

Create XLSX spreadsheets in Ruby with charts, images, styling, auto column sizing, and schema validation; handles large files and eases migration from spreadsheet.

Fixing "A copy of Klass has been removed from the module tree but is still active"

Development error from mixing non-reloading code with autoloaded classes, often after a stale class reference or cached instance keeps an unloaded constant alive.

String#indent: Know your definitions!

String#indent is not part of standard Ruby and may come from gems with unstable internal APIs. Defining it yourself avoids breakage when dependencies change.