Sha256: dd7ac206511ad81473344f9b5829967b64b9f35718ec34864b8310f06fb606ad
Contents?: true
Size: 580 Bytes
Versions: 1
Compression:
Stored size: 580 Bytes
Contents
module Ensurance class Hash def self.ensure(thing) case thing.class.name when "Hash","HashWithIndifferentAccess" thing when "String" JSON.parse(thing) when "NilClass" nil else if thing.respond_to?(:to_h) begin thing.to_h rescue TypeError raise ArgumentError.new("Unhandled Type for Hash to ensure: #{thing.class}") end else raise ArgumentError.new("Unhandled Type for Hash to ensure: #{thing.class}") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ensurance-0.1.0 | lib/ensurance/hash.rb |