Class: HashMap::AfterEachContext

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_map/after_each_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, struct, value) ⇒ AfterEachContext

Returns a new instance of AfterEachContext.



4
5
6
7
8
# File 'lib/hash_map/after_each_context.rb', line 4

def initialize(original, struct, value)
  @original = original
  @struct = struct
  @value = value
end

Instance Attribute Details

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/hash_map/after_each_context.rb', line 3

def original
  @original
end

#structObject (readonly)

Returns the value of attribute struct.



3
4
5
# File 'lib/hash_map/after_each_context.rb', line 3

def struct
  @struct
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/hash_map/after_each_context.rb', line 3

def value
  @value
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/hash_map/after_each_context.rb', line 14

def block?
  !!struct[:proc]
end

#has_key?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hash_map/after_each_context.rb', line 18

def has_key?
  return true if block?
  found = true
  struct[:from].reduce(original) do |prv, nxt|
    unless prv.respond_to?(:key?) && prv.key?(nxt)
      found = false
      break
    end
    prv.send(:[], nxt)
  end
  found
end

#provided?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/hash_map/after_each_context.rb', line 10

def provided?
  has_key?
end