Sha256: 9e2d3283c068a53d39cfa7111d98f44a90d50f7675cb808fe3537f4a07b4e204

Contents?: true

Size: 587 Bytes

Versions: 5

Compression:

Stored size: 587 Bytes

Contents

module CaptainHoog
  class Struct < ::OpenStruct

    def fetch(key, default = nil)
      if not self.respond_to?(key)
        raise IndexError unless default
        return default
      else
        self.public_send(key)
      end
    end

    def method_missing(method_name, *args, &block)
      if self.to_h.respond_to?(method_name)
        self.to_h.stringify_keys.send(method_name.to_s, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      self.to_h.respond_to?(method_name) || super
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
captain_hoog-2.0.0 lib/captain_hoog/struct/hoog_struct.rb
captain_hoog-1.1.1 lib/captain_hoog/struct/hoog_struct.rb
captain_hoog-1.1.0 lib/captain_hoog/struct/hoog_struct.rb
captain_hoog-1.0.2 lib/captain_hoog/struct/hoog_struct.rb
captain_hoog-1.0.1 lib/captain_hoog/struct/hoog_struct.rb