Sha256: f8b3563253547db351d17d219ae64ce3423ef255614bb92bf041cb9683fc8f3c
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
class Hash # Return a new hash with all keys converted to strings. def stringify_keys inject({}) do |options, (key, value)| options[key.to_s] = value options end end # Destructively convert all keys to strings. def stringify_keys! keys.each do |key| self[key.to_s] = delete(key) end self end end class Object # An object is blank if it's false, empty, or a whitespace string. # For example, "", " ", +nil+, [], and {} are blank. # # This simplifies # # if !address.nil? && !address.empty? # # to # # if !address.blank? def blank? respond_to?(:empty?) ? empty? : !self end # An object is present if it's not blank. def present? !blank? end end class NilClass #:nodoc: def blank? true end end class FalseClass #:nodoc: def blank? true end end class TrueClass #:nodoc: def blank? false end end class Array #:nodoc: alias_method :blank?, :empty? end class Hash #:nodoc: alias_method :blank?, :empty? end class String #:nodoc: def blank? self !~ /\S/ end end class Numeric #:nodoc: def blank? false end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
payone_connect-0.1.2 | lib/payone_connect/core_ext.rb |
payone_connect-0.1.1 | lib/payone_connect/core_ext.rb |
payone_connect-0.1.0 | lib/core_ext.rb |