class Toil::Attributes
Public Class Methods
new(hash = {}, &blk)
click to toggle source
# File lib/toil/attributes.rb, line 7 def initialize(hash = {}, &blk) @attributes = hash.each_with_object({}) do |(k, v), h| h[k] = v.is_a?(DynamicValue) ? v : DynamicValue.new(v) end instance_eval(&blk) if block_given? end
Public Instance Methods
[](key)
click to toggle source
# File lib/toil/attributes.rb, line 29 def [](key) (v = @attributes[key]) && v.call end
__set__(key, value = nil, &blk)
click to toggle source
# File lib/toil/attributes.rb, line 33 def __set__(key, value = nil, &blk) @attributes[key] = DynamicValue.new(value, &blk) end
dup(&blk)
click to toggle source
# File lib/toil/attributes.rb, line 18 def dup(&blk) self.class.new(@attributes, &blk) end
method_missing(m, *args, &blk)
click to toggle source
# File lib/toil/attributes.rb, line 14 def method_missing(m, *args, &blk) __set__(m, args.first, &blk) end
to_h(overrides = {})
click to toggle source
# File lib/toil/attributes.rb, line 22 def to_h(overrides = {}) @attributes.each_with_object({}) do |(k, v), h| h[k] = v.call unless overrides.key?(k) end.merge(overrides) end
Also aliased as: to_hash