diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:18:53 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-28 21:18:53 +0000 |
commit | 15d4862b913f6d555ce8a79075d69bba74b5b9bc (patch) | |
tree | 79f4a8e7491d7f20b529d4c495006a4c4e6818d6 /lib | |
parent | 2dafb0f47a7ae70362aea7649b635e97bb33dcf2 (diff) | |
download | ruby-15d4862b913f6d555ce8a79075d69bba74b5b9bc.tar.gz |
* lib/ostruct.rb (each_pair): Add #each_pair [#1400]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ostruct.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 894abce89f..e22fca3e46 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -114,6 +114,20 @@ class OpenStruct end # + # Yields all attributes (as a symbol) along with the corresponding values + # or returns an enumerator if not block is given. + # Example: + # + # require 'ostruct' + # data = OpenStruct.new("country" => "Australia", :population => 20_000_000) + # data.each_pair.to_a # => [[:country, "Australia"], [:population, 20000000]] + # + def each_pair + return to_enum __method__ unless block_given? + @table.each_pair{|p| yield p} + end + + # # Provides marshalling support for use by the Marshal library. # def marshal_dump |