class Arcanus::Chest::Item
Helper class for returning contents nested hashes, exposing helpers to access them via method calls.
Public Class Methods
new(hash, prefix)
click to toggle source
# File lib/arcanus/chest.rb, line 219 def initialize(hash, prefix) @hash = hash @prefix = prefix end
Public Instance Methods
[](key)
click to toggle source
Access the item as if it were a hash.
This will raise an error if the key does not exist, however.
@param key [String] @return [Object]
# File lib/arcanus/chest.rb, line 230 def [](key) if @hash.key?(key) value = @hash[key] if value.is_a?(Hash) Item.new(value, @prefix + [key]) else value end else key_name = "#{@prefix.join('.')}.#{key}" raise KeyError, "Key '#{key_name}' does not exist in this Arcanus chest", caller end end
fetch(*args)
click to toggle source
Fetch key from the chest as if it were a hash.
# File lib/arcanus/chest.rb, line 264 def fetch(*args) @hash.fetch(*args) end
inspect()
click to toggle source
# File lib/arcanus/chest.rb, line 272 def inspect @hash.inspect end
method_missing(method_sym, *args)
click to toggle source
Calls superclass method
# File lib/arcanus/chest.rb, line 246 def method_missing(method_sym, *args) method_name = method_sym.to_s if @hash.key?(method_name) self[method_name] else super end end
respond_to?(method_sym, *)
click to toggle source
Calls superclass method
# File lib/arcanus/chest.rb, line 259 def respond_to?(method_sym, *) @hash.key?(method_sym.to_s) || super end
respond_to_missing?(method_name, *args)
click to toggle source
Calls superclass method
# File lib/arcanus/chest.rb, line 255 def respond_to_missing?(method_name, *args) @hash.key?(method_name.to_s) ? true : super end
to_ary()
click to toggle source
Implicit conversion to array. Needs to be defined so we can `puts` this value.
# File lib/arcanus/chest.rb, line 282 def to_ary [@hash] end
to_hash()
click to toggle source
# File lib/arcanus/chest.rb, line 276 def to_hash @hash.dup end
to_s()
click to toggle source
# File lib/arcanus/chest.rb, line 268 def to_s @hash.to_s end