Module: Tins::IfPredicate
- Included in:
- Object
- Defined in:
- lib/tins/if_predicate.rb
Overview
A module that provides a predicate method for checking if a value is truthy.
The IfPredicate module adds a #if? method to objects that returns true if the object is truthy, and false if it is falsy. This is useful for conditional logic where you want to check if an object evaluates to true in a boolean context.
Instance Method Summary collapse
-
#if? ⇒ Object?
A predicate method that returns the receiver if it’s truthy, or nil if it’s falsy.
Instance Method Details
#if? ⇒ Object?
A predicate method that returns the receiver if it’s truthy, or nil if it’s falsy.
This method is designed to work in conditional expressions where you want to check if a value is truthy and either return it or handle the falsy case.
34 35 36 |
# File 'lib/tins/if_predicate.rb', line 34 def if? self ? self : nil end |