Module: Parliament::Grom::Decorator::Helpers::Utils
- Defined in:
- lib/parliament/grom/decorator/helpers/utils.rb
Overview
Namespace for utility methods
Class Method Summary collapse
-
.type_safe_first(enumerable, klass) ⇒ String
Checks that a collection responds to first and that the first element is of the given class.
Class Method Details
.type_safe_first(enumerable, klass) ⇒ String
Checks that a collection responds to first and that the first element is of the given class
23 24 25 26 27 28 29 30 31 |
# File 'lib/parliament/grom/decorator/helpers/utils.rb', line 23 def type_safe_first(enumerable, klass) return nil unless enumerable.respond_to?(:first) first_element = enumerable.first return nil unless first_element.is_a?(klass) first_element end |