Struct vs Data in Ruby 3.2 data

Struct vs Data in Ruby 3.2

Struct vs Data in Ruby 3.2: what the new immutable Data class does differently, when mutability still makes Struct the right choice, how to extend Data, and benchmarks comparing Data, Struct, and OpenStruct performance.

Apr 15, 2024

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.

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.