From 22115ec87e5c805711762eac46cc5332bf2afb16 Mon Sep 17 00:00:00 2001 From: marcandre Date: Sun, 28 Oct 2012 21:19:32 +0000 Subject: * lib/ostruct.rb: Simplify code git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/ostruct.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/ostruct.rb') diff --git a/lib/ostruct.rb b/lib/ostruct.rb index c00039016a..8fc3de6e72 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -159,15 +159,13 @@ class OpenStruct # # Used internally to defined properties on the # OpenStruct. It does this by using the metaprogramming function - # define_method for both the getter method and the setter method. + # define_singleton_method for both the getter method and the setter method. # def new_ostruct_member(name) name = name.to_sym - unless self.respond_to?(name) - class << self; self; end.class_eval do - define_method(name) { @table[name] } - define_method("#{name}=") { |x| modifiable[name] = x } - end + unless respond_to?(name) + define_singleton_method(name) { @table[name] } + define_singleton_method("#{name}=") { |x| modifiable[name] = x } end name end -- cgit v1.2.3