Mastering Ruby Keyword Arguments: Syntax, Defaults, and Common Pitfalls
Learn how to define and call Ruby methods with keyword arguments, set defaults, use **kwargs, and avoid common pitfalls. Practical example and best‑practice tips included.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how to define and call Ruby methods with keyword arguments, set defaults, use **kwargs, and avoid common pitfalls. Practical example and best‑practice tips included.
RSpec's aggregate_failures collects every failed expectation in an example instead of stopping at the first. Here's how to enable it, where it pays off, and where it backfires.
Learn how Ruby keyword arguments eliminate positional confusion, enforce required parameters, and simplify API evolution with clear, self‑documenting method signatures.
Replace nested conditionals with declarative case/in patterns when processing varied webhook payloads in Ruby 3.x.
Centralize reusable expectations with RSpec shared_examples, but watch for coupling and obscured intent. A practical guide with parameterized examples.
Decide between one expectation per example, plain multiple expectations, and RSpec's :aggregate_failures based on setup cost and assertion independence — with a working request-spec example and a validation procedure.
Master RSpec’s shared_examples to cut test duplication—define once, reuse everywhere, and verify with dry‑run and documentation output.
Ruby 3.0 removed implicit Hash-to-keyword conversion, breaking legacy call sites. This post explains the change, shows how to migrate wrapper patterns with double-splat, and when keywords actually improve clarity versus adding noise.
Copying RSpec tests across multiple spec files becomes a maintenance nightmare. Shared examples let you write a single test suite that can be applied to any number of classes, keeping your spec suite DRY while guaranteeing interface consistency.