Class: Radius::DelegatingOpenStruct

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object = nil) ⇒ DelegatingOpenStruct

Returns a new instance of DelegatingOpenStruct


5
6
7
8
# File 'lib/radius/delegating_open_struct.rb', line 5

def initialize(object = nil)
  @object = object
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/radius/delegating_open_struct.rb', line 16

def method_missing(method, *args, &block)
  symbol = (method.to_s =~ /^(.*?)=$/) ? $1.intern : method
  if (0..1).include?(args.size)
    if args.size == 1
      @hash[symbol] = args.first
    else
      if @hash.has_key?(symbol)
        @hash[symbol]
      else
        unless object.nil?
          @object.send(method, *args, &block)
        else
          nil
        end
      end
    end
  else
    super
  end
end

Instance Attribute Details

#objectObject

Returns the value of attribute object


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

def object
  @object
end

Instance Method Details

#dupObject


10
11
12
13
14
# File 'lib/radius/delegating_open_struct.rb', line 10

def dup
  rv = self.class.new
  rv.instance_variable_set(:@hash, @hash.dup)
  rv
end