💡 TIL: Ruby can chain methods and right-assign
29th October 2024
I just learned that ruby supports re-writing this:
total = plus_shipping(with_taxes(subtotal(items)))
As:
subtotal(items).then { |subtotal| with_taxes(subtotal) }.then { |total| plus_shipping(total) } => totalfrom davetron
More recent articles
- Ruby's clamp method reduces conditionals - 24th February 2025
- Regex within string square brackets - 24th February 2025
- Elegant solution to versioning an API - 24th February 2025