Class: Hashay

Inherits:
Hash show all
Includes:
Enumerable
Defined in:
lib/kiss/form.rb

Overview

Part Hash, part Array… it’s a Hashay.

Instance Method Summary collapse

Methods included from Enumerable

#conjoin, #hash_arrays_by_id, #hash_arrays_by_key, #hash_arrays_by_keys, #hash_by_id, #hash_by_key, #hash_by_keys, #hash_pairs, #hash_values_by_key, #hash_values_by_keys, #hash_with_keys, #ids, #join_unless_empty, #to_table

Methods inherited from Hash

#id, #method_missing, #prepend_html, #to_query_string, #type

Constructor Details

#initialize(*args, &block) ⇒ Hashay

Returns a new instance of Hashay.



7
8
9
10
11
# File 'lib/kiss/form.rb', line 7

def initialize(*args, &block)
  super
  @_keys = []
  @_values = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hash

Instance Method Details

#[](key) ⇒ Object



30
31
32
# File 'lib/kiss/form.rb', line 30

def [](key)
  key.is_a?(Numeric) ? @_values[key] : super
end

#[]=(key, value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/kiss/form.rb', line 22

def []=(key, value)
  unless has_key?(key)
    @_keys << key
    @_values << value 
  end
  super
end

#each_key(&block) ⇒ Object



13
14
15
# File 'lib/kiss/form.rb', line 13

def each_key(&block)
  @_keys.each &block
end

#each_value(&block) ⇒ Object Also known as: each



17
18
19
# File 'lib/kiss/form.rb', line 17

def each_value(&block)
  @_values.each &block
end