Class: Inquisitive::Hash

Inherits:
HashWithIndifferentAccess show all
Includes:
Inquisitive
Defined in:
lib/inquisitive/hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inquisitive

[], present?

Methods inherited from HashWithIndifferentAccess

[], #[]=, #assert_valid_keys, #default, #delete, #extractable_options?, #fetch, #initialize, #key?, #merge, #nested_under_indifferent_access, #regular_update, #regular_writer, #replace, #select, #steal_default_from, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_hash, #to_options!, #transform_keys, #transform_keys!, #update, #values_at, #with_indifferent_access

Constructor Details

This class inherits a constructor from Inquisitive::HashWithIndifferentAccess

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object (private)



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/inquisitive/hash.rb', line 23

def method_missing(method_name, *arguments)
  if predicate_method? method_name
    if has_key? predication(method_name)
      Inquisitive.present? self[predication(method_name)]
    else
      false
    end ^ negated
  elsif has_key? method_name
    self[method_name]
  else
    super
  end
end

Instance Attribute Details

#negatedObject

Returns the value of attribute negated.



5
6
7
# File 'lib/inquisitive/hash.rb', line 5

def negated
  @negated
end

Instance Method Details

#convert_value(value, options = {}) ⇒ Object



10
11
12
# File 'lib/inquisitive/hash.rb', line 10

def convert_value(value, options={})
  super(Inquisitive[value], options)
end

#noObject



6
7
8
# File 'lib/inquisitive/hash.rb', line 6

def no
  dup.tap{ |s| s.negated = !s.negated }
end