Sha256: c7717d71f23c9f8db68fa319955ce7ebb4cc427f4f42fa3cb1b06f90aa9c4a4f
Contents?: true
Size: 1.07 KB
Versions: 25
Compression:
Stored size: 1.07 KB
Contents
module Compony # @api description # This class is intended for configs with predefined interfaces and should be used with instances of Hash:<br> # Example:<br> # ```ruby # instance_of_a_hash = Compony::MethodAccessibleHash.new # instance_of_a_hash.merge!({ foo: :bar }) # instance_of_a_hash.foo --> :bar # instance_of_a_hash.roo --> nil # ``` # See: https://gist.github.com/kalsan/87826048ea0ade92ab1be93c0919b405 class MethodAccessibleHash < Hash # Takes an optional hash as argument and constructs a new # MethodAccessibleHash. def initialize(hash = {}) super() hash.each do |key, value| self[key.to_sym] = value end end # @private def merge(hash) super(hash.symbolize_keys) end # @private def method_missing(method, *args, &) if method.end_with?('=') name = method.to_s.gsub(/=$/, '') self[name.to_sym] = args.first else self[method.to_sym] end end # @private def respond_to_missing?(_method, _include_private = false) true end end end
Version data entries
25 entries across 25 versions & 1 rubygems