summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 15:58:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 15:58:18 +0000
commitc0acb3ce179ff038ee24f608a3615069645a7799 (patch)
tree86c583626c2dee0f1c4fdafab877423cd0af7b60 /lib/ostruct.rb
parentcb32ebe81c0d02a430d016cbdfd93960ec0b259d (diff)
* io.c (rb_io_sysread): use temporary lock. [ruby-dev:24992]
* lib/ostruct.rb (OpenStruct::method_missing): check method duplication for -d. * lib/ostruct.rb (OpenStruct::initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r--lib/ostruct.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 8d8484caf5..4d9bb33606 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -47,6 +47,9 @@ class OpenStruct
@table = {}
if hash
for k,v in hash
+ if $DEBUG and self.respond_to?(k, true)
+ raise NameError, "already existing member #{k}", caller(2)
+ end
@table[k.to_sym] = v
end
end
@@ -58,13 +61,6 @@ class OpenStruct
@table = @table.dup
end
- def new_ostruct_member(name)
- self.instance_eval %{
- def #{name}; @table[:#{name}]; end
- def #{name}=(x); @table[:#{name}] = x; end
- }
- end
-
def method_missing(mid, *args) # :nodoc:
mname = mid.id2name
len = args.length
@@ -76,8 +72,10 @@ class OpenStruct
raise TypeError, "can't modify frozen #{self.class}", caller(1)
end
mname.chop!
+ if $DEBUG and self.respond_to?(mname, true)
+ raise NameError, "already existing member #{mname}", caller(1)
+ end
@table[mname.intern] = args[0]
- self.new_ostruct_member(mname)
elsif len == 0
@table[mid]
else