Class: Typed::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/typed/default.rb

Instance Method Summary collapse

Constructor Details

#initialize(kvs) ⇒ Default

Returns a new instance of Default.



3
4
5
# File 'lib/typed/default.rb', line 3

def initialize(kvs)
  @kvs = kvs
end

Instance Method Details

#[]=(key, val) ⇒ Object



7
8
9
10
# File 'lib/typed/default.rb', line 7

def []=(key, val)
  return if @kvs.exist?(key)
  @kvs[key] = val
end

#regsiter_lazy(key, block) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/typed/default.rb', line 12

def regsiter_lazy(key, block)
  return if @kvs.exist?(key)
  raise ArgumentError, "Lazy default value needs block: #{key}" unless block
  @kvs[key] = LazyValue.new(block)
end