class Liquid::Drop::HashOrArray

Constants

VERSION

Public Class Methods

new(data) click to toggle source

– @return [<HashOrArray>] the instance There is no need for explaining it. –

# File lib/liquid/drop/hash_or_array.rb, line 17
def initialize(data)
  @data = data
end

Public Instance Methods

[](key) click to toggle source

– @return [<Any>] the value or nil. Standard hash method so that you can also access

the data like a hash/array.

# File lib/liquid/drop/hash_or_array.rb, line 26
def [](key)
  liquid_method_missing(key)
end
liquid_method_missing(key) click to toggle source

– Uses Liquids method missing method to get the key

when you try and access the drop like a chained method
we do the case because oen day we might split out the
class and it would require minimal refactor.

@return [<Any>] the value or nil. –

# File lib/liquid/drop/hash_or_array.rb, line 37
def liquid_method_missing(key)
  val = @data.fetch(key.to_s, @data[key.to_sym])

  case true
  when val.is_a?(Array) then HashOrArray.new(val)
  when val.is_a?( Hash) then HashOrArray.new(val)
  else
    val
  end
end