Class: Dotaccess::Proxy

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

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Proxy

Returns a new instance of Proxy.



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

def initialize(hash)
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/flutterby/dotaccess.rb', line 7

def method_missing(meth, *args)
  if @hash.respond_to?(meth)
    @hash.send(meth, *args)
  elsif meth =~ %r{\A(.+)=\Z}
    @hash[$1] = args.first
  elsif v = (@hash[meth] || @hash[meth.to_s])
    v.is_a?(Hash) ? Proxy.new(v) : v
  else
    nil
  end
end

Instance Method Details

#==(o) ⇒ Object



23
24
25
# File 'lib/flutterby/dotaccess.rb', line 23

def ==(o)
  @hash == o
end

#[](k) ⇒ Object



19
20
21
# File 'lib/flutterby/dotaccess.rb', line 19

def [](k)
  @hash[k]
end