Sha256: a911dc9ab0cb3db75236a4c18bb1064ce96257ead9f601174960be3f99eb6947

Contents?: true

Size: 682 Bytes

Versions: 6

Compression:

Stored size: 682 Bytes

Contents

# Copied from the DeepStruct gem
# Modified to return Null on unknown key
module DeepStruct
  class HashWrapper < DeepWrapper
    def method_missing(method, *args, &block)
      return @value.send(method, *args, &block) if @value.respond_to?(method)
      method = method.to_s
      if method.chomp!('?')
        key = method.to_sym
        self.has_key?(key) && !!self[key]
      elsif method.chomp!('=')
        raise ArgumentError, "wrong number of arguments (#{arg_count} for 1)", caller(1) if args.length != 1
        self[method] = args[0]
      elsif args.length == 0 && self.has_key?(method)
        self[method]
      else
        Hem::Null.new
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hem-1.0.1.beta6 lib/hem/patches/deepstruct.rb
hem-1.0.1.beta5 lib/hem/patches/deepstruct.rb
hem-1.0.1.beta4 lib/hem/patches/deepstruct.rb
hem-1.0.1.beta3 lib/hem/patches/deepstruct.rb
hem-1.0.1.beta2 lib/hem/patches/deepstruct.rb
hem-1.0.1.beta1 lib/hem/patches/deepstruct.rb