cupid
cupid
ruby
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.
ruby
Ruby Hash destruction like from Javascript world (and reconstruction)
Ruby hash destructuring can feel as smooth as JavaScript: the rightward pattern matching syntax extracts values from a hash in one line, renames them, destructures arrays, groups elements, and rebuilds hashes afterwards. Practical examples for cleaner Ruby code.
Latest
Enums with Typescript - why it's bad? Possible solutions
TypeScript enums generate extra JavaScript at compile time and numeric enums are not even type-safe. Why enums can hurt bundle size and correctness, and two safer alternatives: assigning explicit string values or replacing enums with plain objects.
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
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.
Ruby SOLID in practice with minimizing nesting rule
SOLID in Ruby with working code for every principle: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion, plus a bonus rule on minimizing nesting and a fair look at the criticisms of SOLID.