Powerful switch statement with pattern matching in Ruby ruby

Powerful switch statement with pattern matching in Ruby

Pattern matching in Ruby turns case statements into a precise switch over data shapes: match and destructure hashes from an API response, combine several patterns in one branch, capture values across patterns, and validate configuration. Ruby 2.7+ syntax examples.

Jul 17, 2023

Monolith vs microservices vs serverless

Monolith vs microservices vs serverless

Monolith, microservices, or serverless? A side by side comparison of how each backend architecture handles scaling, development speed, deployment, and cost, where each one breaks down in practice, and a summary that helps you pick the right fit for your project.

How to set up XML in Grape API

How to set up XML in Grape API

XML support in Grape API takes two steps: register the additional content_type so endpoints accept and return application/xml, then change the root element name of the XML output. Complete Ruby examples built around a products endpoint you can adapt to your API.

Multiple ways to execute a shell command via Ruby

Multiple ways to execute a shell command via Ruby

Running shell commands from Ruby: system, backticks, exec, the IO class, spawn, and Open3.popen3 compared with pros and cons, from quick one-liners to capturing stdout, stderr, and exit status, so you can pick the right method for scripts and production code.

Database shrading and database partitioning in Rails

Database shrading and database partitioning in Rails

Database sharding in Rails step by step: create a separate database per shard, wire them up in database.yml, and query across them. Plus how sharding differs from partitioning, with a native PostgreSQL partitioning example done through Rails migrations.

Sidekiq basic_fetch and super_fetch differences

Sidekiq basic_fetch and super_fetch differences

Sidekiq basic_fetch vs super_fetch: open source Sidekiq fetches jobs with BRPOP and loses them when a process crashes, while Sidekiq Pro's super_fetch uses RPOPLPUSH with private per-process queues to recover orphaned jobs. What that means for queue reliability.

Understanding generic types in Typescript

Understanding generic types in Typescript

Generic types in TypeScript let one function, class, or interface work safely with many data types. What generics are, how a type parameter beats hardcoding a concrete entity type in a validation helper, and honest pros and cons before you use them everywhere.

Rails eager_load, joins and includes - when to use what

Rails eager_load, joins and includes - when to use what

Rails eager_load, includes, preload, and joins each fight slow queries differently: LEFT OUTER JOIN versus separate queries, how includes picks its strategy, and when a plain joins is enough. Clear examples showing which loading method to choose for each situation.

Ruby in browser via WebAssembly

Ruby in browser via WebAssembly

Ruby 3.2 runs in the browser through WebAssembly: embed Ruby in a script tag with ruby-wasm-wasi or drive the Ruby VM from JavaScript and mix it with HTML. Working examples plus honest limits: no threading or networking, and no extra gems without a custom wasm image.

Solutions for const and enums per class in Ruby

Solutions for const and enums per class in Ruby

Three ways to define constants and enums per class in Ruby: the ActiveRecord enum macro, a mixed style combining frozen constants with enum, and a dependency-free PORO version. Code for each solution and a comparison to help you pick the right one.

Factory Pattern with auto-detecting classes in Ruby

Factory Pattern with auto-detecting classes in Ruby

The Factory Pattern in Ruby, then a step further: using naming conventions and regular expressions so the factory auto-detects which notification class to instantiate. Complete code for both versions, plus when strict class listing is the safer choice.

Map vs WeakMap in practice

Map vs WeakMap in practice

Map vs WeakMap in JavaScript comes down to keys and memory: WeakMap only accepts object keys and lets garbage collection reclaim unused entries, while Map holds onto everything. Differences, similarities, and practical guidance on when each one is the right choice.

Anonymous Arguments Passing Improvements in Ruby 3.2

Anonymous Arguments Passing Improvements in Ruby 3.2

Ruby 3.2 adds new syntax for anonymous arguments: forward positional and keyword arguments with bare * and ** and unpack them inside the method, no more digging through kwargs hashes. A before-and-after example shows how much cleaner argument passing gets.

How to write Naive Bayes classification algorithm in Ruby

How to write Naive Bayes classification algorithm in Ruby

Naive Bayes classification in plain Ruby: how prior and posterior probabilities decide the winning class, then a working spam filter that classifies email titles. Also where the algorithm shines: sentiment analysis, recommendations, and fraud detection.