Sha256: 20e55e5ee8cf28235210067df40b86dbe3a1a2af65b4f5d3430594649928f0f0

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

module Radius
  class DelegatingOpenStruct # :nodoc:
    attr_accessor :object
    
    def initialize(object = nil)
      @object = object
      @hash = {}
    end

    def dup
      self.class.new.tap do |copy|
        copy.instance_variable_set(:@hash, @hash.dup)
        copy.object = @object
      end
    end
    
    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

    def respond_to_missing?(method, include_private = false)
      (args.size <= 1) || super
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/radius-0.8.0/lib/radius/delegating_open_struct.rb
radius-0.8.0 lib/radius/delegating_open_struct.rb