Module: Unbounded::Utility
- Extended by:
- ActiveSupport::Concern, Utility
- Defined in:
- lib/unbounded/utility.rb
Overview
Shared utility methods
Instance Method Summary collapse
-
#match_to_hash(match) ⇒ Hash
Convert matchdata to a hash.
- #numerify(thing, default_value = nil) ⇒ Numeric, ...
Instance Method Details
#match_to_hash(match) ⇒ Hash
Convert matchdata to a hash.
11 12 13 |
# File 'lib/unbounded/utility.rb', line 11 def match_to_hash(match) Hash[match.names.zip(match.captures)] end |
#numerify(thing, default_value = nil) ⇒ Numeric, ...
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/unbounded/utility.rb', line 19 def numerify(thing, default_value = nil) return thing if thing.is_a?(Numeric) if thing.respond_to?(:include?) && thing.include?('.') Float(thing) else Integer(thing) end rescue ArgumentError, TypeError if default_value == :original thing else default_value end end |