Class: Prefab::Context::NamedContext

Inherits:
Object
  • Object
show all
Defined in:
lib/prefab/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hash) ⇒ NamedContext

Returns a new instance of NamedContext.



10
11
12
13
14
15
# File 'lib/prefab/context.rb', line 10

def initialize(name, hash)
  @hash = {}
  @name = name.to_s

  merge!(hash)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/prefab/context.rb', line 8

def name
  @name
end

Instance Method Details

#get(parts) ⇒ Object



17
18
19
# File 'lib/prefab/context.rb', line 17

def get(parts)
  @hash[parts]
end

#merge!(other) ⇒ Object



21
22
23
# File 'lib/prefab/context.rb', line 21

def merge!(other)
  @hash = @hash.merge(other.transform_keys(&:to_s))
end

#to_hObject



25
26
27
# File 'lib/prefab/context.rb', line 25

def to_h
  @hash
end