Class: Lab42::NHash::Enum
- Inherits:
-
Object
- Object
- Lab42::NHash::Enum
- Extended by:
- Forwarder
- Includes:
- Enumerable, Invocation
- Defined in:
- lib/lab42/nhash/enum.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #each(blk = nil, &block) ⇒ Object
- #fetch!(idx) ⇒ Object
- #get(keyexp = nil, &block) ⇒ Object
Instance Attribute Details
#parent ⇒ Object (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
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 |