1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/ostruct.rb: Simplify code

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2012-10-28 21:19:32 +00:00
parent b4300d25c9
commit 22115ec87e

View file

@ -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