Sha256: 86f446229e09afa0680b6e303cd95e4beacb73c291730529ca58ff20527090bd
Contents?: true
Size: 711 Bytes
Versions: 1
Compression:
Stored size: 711 Bytes
Contents
require "uber/delegates" module Declarative class Defaults def initialize @static_options = {} @dynamic_options = ->(*) { Hash.new } end def merge!(hash, &block) @static_options.merge!(hash) if hash.any? @dynamic_options = block if block_given? self end extend Uber::Delegates delegates :@static_options, :[], :[]= # mutuable API! # TODO: allow to receive rest of options/block in dynamic block. or, rather, test it as it was already implemented. def call(name, given_options) options = @static_options options = options.merge(@dynamic_options.(name, given_options)) options = options.merge(given_options) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
declarative-0.0.7 | lib/declarative/defaults.rb |