Class: RubyInstaller::Build::Openstruct

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_installer/build/openstruct.rb

Direct Known Subclasses

Task

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Openstruct

Returns a new instance of Openstruct.



4
5
6
7
8
9
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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