diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:19:32 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:19:32 +0000 |
commit | 22115ec87e5c805711762eac46cc5332bf2afb16 (patch) | |
tree | e05da7ffe461ece30377c902c8fce152bfa48307 /lib/ostruct.rb | |
parent | b4300d25c941475db902ed2dc667ac23d36be992 (diff) |
* lib/ostruct.rb: Simplify code
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 10 |
1 files changed, 4 insertions, 6 deletions
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 |