123456789_123456789_123456789_123456789_123456789_

Class: RubyInstaller::Build::Openstruct

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/ruby_installer/build/openstruct.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(hash = {}) ⇒ Openstruct

[ GitHub ]

  
# File 'lib/ruby_installer/build/openstruct.rb', line 4

def initialize(hash={})
  @__attrs = {}
  hash.each do |k,v|
    send("#{k}=", v)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args)

[ GitHub ]

  
# File 'lib/ruby_installer/build/openstruct.rb', line 11

def method_missing(meth, *args)
  if meth=~/\A(.*)=\z/ && args.length == 1
    attr = $1
    self.class.class_eval do
      define_method(attr) do
        @__attrs[attr]
      end
      define_method(meth) do |val|
        @__attrs[attr] = val
      end
    end
    @__attrs[attr] = args.first
  else
    super
  end
end