Class: Radius::DelegatingOpenStruct
- Inherits:
-
Object
- Object
- Radius::DelegatingOpenStruct
- Defined in:
- lib/radius/dostruct.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object = nil) ⇒ DelegatingOpenStruct
constructor
A new instance of DelegatingOpenStruct.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(object = nil) ⇒ DelegatingOpenStruct
Returns a new instance of DelegatingOpenStruct.
5 6 7 8 |
# File 'lib/radius/dostruct.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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/radius/dostruct.rb', line 10 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
#object ⇒ Object
Returns the value of attribute object.
3 4 5 |
# File 'lib/radius/dostruct.rb', line 3 def object @object end |