Sha256: 62c475720005f3f72a543c3632bff3747c0424b9a1a9c5a2778958d70a6d1338
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
class Hash # Methodize this hash def methodize!(recursive = true) self.extend(Methodize) if recursive self.values.each do |val| case val when Hash val.methodize!(recursive) when Array val.methodize_hashes!(recursive) end end end end # Makes a fully recursive merge def noe_merge(right, stack = "") self.merge(right) do |key,oldval,newval| if oldval.nil? or newval.nil? newval elsif [true, false].include?(oldval) && [true, false].include?(newval) newval elsif oldval.class != newval.class raise Noe::Error, "Conflict on #{stack} has to be resolved manually, sorry.\n"\ "#{oldval} (#{oldval.class}) vs. #{newval} (#{newval.class})" elsif oldval.respond_to?(:noe_merge) oldval.noe_merge(newval, "#{stack}/#{key}") else newval end end end module Methodize # Allows using hash.key as a synonym for hash[:key] and # hash['key'] def method_missing(name, *args, &block) if args.empty? and block.nil? self[name] || self[name.to_s] else super(name, *args, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
noe-1.3.0 | lib/noe/ext/hash.rb |