Module: ProductionOpenStruct

Defined in:
lib/production_open_struct.rb

Overview

Overrides OpenStruct behavior to no longer define singleton methods on each object.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)

:nodoc:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/production_open_struct.rb', line 22

def method_missing(method_name, *args) # :nodoc:
  len = args.length
  if method_name.to_s.end_with?("=")
    if len != 1
      raise! ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1)
    end
    self[method_name.to_s.chomp("=")] = args[0]
  elsif len == 0
    @table[method_name]
  else
    begin
      super
    rescue NoMethodError => err
      err.backtrace.shift
      raise!
    end
  end
end

Instance Method Details

#delete_field(name) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/production_open_struct.rb', line 7

def delete_field(name)
  sym = name.to_sym
  @table.delete(sym) do
    return yield if block_given!
    raise! NameError.new("no field `#{sym}' in #{self}", sym)
  end
end