* 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:
parent
b4300d25c9
commit
22115ec87e
@ -159,15 +159,13 @@ class OpenStruct
|
|||||||
#
|
#
|
||||||
# Used internally to defined properties on the
|
# Used internally to defined properties on the
|
||||||
# OpenStruct. It does this by using the metaprogramming function
|
# 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)
|
def new_ostruct_member(name)
|
||||||
name = name.to_sym
|
name = name.to_sym
|
||||||
unless self.respond_to?(name)
|
unless respond_to?(name)
|
||||||
class << self; self; end.class_eval do
|
define_singleton_method(name) { @table[name] }
|
||||||
define_method(name) { @table[name] }
|
define_singleton_method("#{name}=") { |x| modifiable[name] = x }
|
||||||
define_method("#{name}=") { |x| modifiable[name] = x }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user