summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 21:19:50 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-28 21:19:50 +0000
commit3785d2675abf2e4aca07e89596ea6f12b4c474a5 (patch)
tree9932e8e24868b0bb49ba2e8f7be7bbf1312d519c /lib/ostruct.rb
parent22115ec87e5c805711762eac46cc5332bf2afb16 (diff)
* lib/ostruct.rb: Also accept {Open}Struct as argument to new
[ruby-core:47476] [Feature #7007] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r--lib/ostruct.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 8fc3de6..17b3ab0 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -74,7 +74,8 @@ class OpenStruct
# Creates a new OpenStruct object. By default, the resulting OpenStruct
# object will have no attributes.
#
- # The optional +hash+, if given, will generate attributes and values.
+ # The optional +hash+, if given, will generate attributes and values
+ # (can be a Hash, an OpenStruct or a Struct).
# For example:
#
# require 'ostruct'
@@ -86,8 +87,9 @@ class OpenStruct
def initialize(hash=nil)
@table = {}
if hash
- for k,v in hash
- @table[k.to_sym] = v
+ hash.each_pair do |k, v|
+ k = k.to_sym
+ @table[k] = v
new_ostruct_member(k)
end
end