Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hash.rb', line 14

def method_missing(method, *args)
  return super(method, *args) unless to_dot?

  prop = create_prop(method)

  if setter?(method)
    self[prop] = args.first
  else
    super(method, args) && return unless key?(prop)
    self[prop]
  end
end

Class Attribute Details

.use_dot_syntaxObject

Returns the value of attribute use_dot_syntax.



3
4
5
# File 'lib/hash.rb', line 3

def use_dot_syntax
  @use_dot_syntax
end

Instance Attribute Details

#use_dot_syntaxObject

Returns the value of attribute use_dot_syntax.



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

def use_dot_syntax
  @use_dot_syntax
end

Instance Method Details

#respond_to?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/hash.rb', line 27

def respond_to?(method, include_all=false)
  return super(method, include_all) unless to_dot?
  prop = create_prop(method)
  return true if key?(prop)
  super(method, include_all)
end

#to_dotObject



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

def to_dot
  dotify_hash(self)

  self
end