module Unbounded::Utility
Shared utility methods
Public Instance Methods
match_to_hash(match)
click to toggle source
Convert matchdata to a hash. @param [MatchData] match @return [Hash]
# File lib/unbounded/utility.rb, line 11 def match_to_hash(match) Hash[match.names.zip(match.captures)] end
numerify(thing, default_value = nil)
click to toggle source
@param [Object] thing something to numerify @param [Object] default_value a value to return if `thing` fails to numerify.
If it is `:original`, it will return the value of `thing` as-is.
@return [Numeric, Object, nil]
# 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