Project

General

Profile

Bug #1219 ยป ostruct.patch

The patch for lib/ostruct.rb - RobertDober (Robert Dober), 02/27/2009 06:11 AM

View differences:

ostruct.new.rb 2009-02-26 22:02:32.000000000 +0100
59 59
    @table = @table.dup
60 60
  end
61 61

  
62
  def freeze
63
    @table.freeze 
64
  end
65
  
62 66
  def marshal_dump
63 67
    @table
64 68
  end
......
72 76
    unless self.respond_to?(name)
73 77
      class << self; self; end.class_eval do
74 78
        define_method(name) { @table[name] }
75
        define_method(:"#{name}=") { |x| @table[name] = x }
79
        define_method(:"#{name}=") { |x| set_table name, x }
76 80
      end
77 81
    end
78 82
  end
......
84 88
      if len != 1
85 89
        raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
86 90
      end
87
      if self.frozen?
88
        raise TypeError, "can't modify frozen #{self.class}", caller(1)
89
      end
90 91
      mname.chop!
91 92
      self.new_ostruct_member(mname)
92
      @table[mname.intern] = args[0]
93
      set_table mname.intern, args.first
93 94
    elsif len == 0
94 95
      @table[mid]
95 96
    else
......
135 136
  attr_reader :table # :nodoc:
136 137
  protected :table
137 138

  
139
  def set_table key, value # :nodoc:
140
    @table[ key ] = value
141
  rescue RuntimeError => e
142
    raise TypeError, "can't modify frozen #{self.class}", caller(1)
143
  end
144
  private :set_table
138 145
  #
139 146
  # Compare this object and +other+ for equality.
140 147
  #