Class: RestCore::Clash

Inherits:
Object
  • Object
show all
Defined in:
lib/rest-core/util/clash.rb

Constant Summary collapse

Empty =
Hash.new(&(l = lambda{|_,_|Hash.new(&l).freeze})).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Clash

Returns a new instance of Clash.



7
8
9
# File 'lib/rest-core/util/clash.rb', line 7

def initialize data
  self.data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args, &block) ⇒ Object (private)



43
44
45
46
47
48
49
# File 'lib/rest-core/util/clash.rb', line 43

def method_missing msg, *args, &block
  if data.respond_to?(msg)
    data.public_send(msg, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/rest-core/util/clash.rb', line 6

def data
  @data
end

Instance Method Details

#==(rhs) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rest-core/util/clash.rb', line 19

def == rhs
  if rhs.kind_of?(RestCore::Clash)
    data == rhs.data
  else
    data == rhs
  end
end

#[](k) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rest-core/util/clash.rb', line 11

def [] k
  if data.key?(k)
    convert(data[k])
  else
    Empty
  end
end