💡 TIL: Ruby’s clamp method reduces conditionals
24th February 2025
You can constrain a variable to be within a range using clamp:
5.clamp(1, 10) # => 5 -3.clamp(1, 10) # => 1 15.clamp(1, 10) # => 10
More recent articles
- with_defaults is a better named alias - 28th April 2025
- Bundler can be configured to auto install - 28th April 2025
- React in Rails is gaining momentum with Inertia - 14th April 2025