Class: Lab42::NHash::Enum

Inherits:
Object
  • Object
show all
Extended by:
Forwarder
Includes:
Enumerable, Invocation
Defined in:
lib/lab42/nhash/enum.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



18
19
20
# File 'lib/lab42/nhash/enum.rb', line 18

def parent
  @parent
end

Instance Method Details

#[](idx) ⇒ Object



20
21
22
# File 'lib/lab42/nhash/enum.rb', line 20

def [] idx
  Lab42::NHash.from_value @enum[idx], @options
end

#each(blk = nil, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/lab42/nhash/enum.rb', line 24

def each blk=nil, &block
  behavior = blk || block
  @enum.each do | ele |
    behavior.( Lab42::NHash.from_value ele, @options )
  end
end

#fetch!(idx) ⇒ Object



31
32
33
34
35
36
# File 'lib/lab42/nhash/enum.rb', line 31

def fetch! idx
  result = self[ idx ]
  return result unless String === result

  ERB.new( result ).result @parent.current_binding
end

#get(keyexp = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
# File 'lib/lab42/nhash/enum.rb', line 38

def get keyexp=nil, &block
  behavior = block || keyexp
  raise ArgumentError, 'need key or behavior' unless behavior
  Proc === behavior ? _get_with_behavior( behavior ) : _get_with_key( keyexp )
end