Class: Radius::DelegatingOpenStruct
- Inherits:
-
Object
- Object
- Radius::DelegatingOpenStruct
- Defined in:
- lib/radius/delegating_open_struct.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #dup ⇒ Object
-
#initialize(object = nil) ⇒ DelegatingOpenStruct
constructor
A new instance of DelegatingOpenStruct.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(object = nil) ⇒ 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
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/radius/delegating_open_struct.rb', line 17 def method_missing(method, *args, &block) return super if args.size > 1 symbol = method.to_s.chomp('=').to_sym if method.to_s.end_with?('=') @hash[symbol] = args.first else @hash.fetch(symbol) { @object&.public_send(method, *args, &block) } end end |
Instance Attribute Details
#object ⇒ Object
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
#dup ⇒ Object
10 11 12 13 14 15 |
# File 'lib/radius/delegating_open_struct.rb', line 10 def dup self.class.new.tap do |copy| copy.instance_variable_set(:@hash, @hash.dup) copy.object = @object end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
29 30 31 |
# File 'lib/radius/delegating_open_struct.rb', line 29 def respond_to_missing?(method, include_private = false) (args.size <= 1) || super end |