Class: ApiBomb::LambdaHash

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/api_bomb/lambda_hash.rb

Overview

values can respond to call making them dynamic

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hasharize(hash) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/api_bomb/lambda_hash.rb', line 3

def self.hasharize(hash)
  hash_call = self.new(hash)
  h = {}
  hash_call.each do |v, k|
    h[v] = hash_call[v]
    if h[v].is_a? self
      h[v] = self.hasharize(h[v])
    end
  end

  return h
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/api_bomb/lambda_hash.rb', line 32

def [](key)
  value = self.__getobj__[key]
  value = value.call if value.respond_to? :call
  value =  self.class.new(value) if value.is_a? Hash

  return value
end

#is_lambda?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/api_bomb/lambda_hash.rb', line 16

def is_lambda?
  return false if self.blank?

  self.each do |k,v|
    if self[k].is_a? self.class
      return self[k].is_lambda?
    else
      if self.real[k].respond_to? :call
        return true
      else
        return false
      end
    end
  end
end

#realObject



40
41
42
# File 'lib/api_bomb/lambda_hash.rb', line 40

def real
  self.__getobj__
end