Class: Riddler::Drops::HashDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/riddler/drops/hash_drop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashDrop

Returns a new instance of HashDrop.



7
8
9
# File 'lib/riddler/drops/hash_drop.rb', line 7

def initialize hash
  @hash = Hash[ hash.map { |k,v| [k.to_s, v] } ]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args) ⇒ Object



23
24
25
# File 'lib/riddler/drops/hash_drop.rb', line 23

def method_missing method, *_args
  liquid_method_missing method.to_s
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/riddler/drops/hash_drop.rb', line 5

def hash
  @hash
end

Instance Method Details

#[]=(key, value) ⇒ Object



11
12
13
# File 'lib/riddler/drops/hash_drop.rb', line 11

def []= key, value
  @hash[key.to_s] = value
end

#liquid_method_missing(method) ⇒ Object



15
16
17
# File 'lib/riddler/drops/hash_drop.rb', line 15

def liquid_method_missing method
  @hash[method]
end

#to_hashObject



19
20
21
# File 'lib/riddler/drops/hash_drop.rb', line 19

def to_hash
  hash
end