diff options
author | Austin Ziegler <austin@zieglers.ca> | 2014-05-22 23:49:21 -0400 |
---|---|---|
committer | Austin Ziegler <austin@zieglers.ca> | 2014-10-06 23:57:27 -0400 |
commit | 1db8f2ad61cb5d1fe42605f1a83e9d0d529e0731 (patch) | |
tree | 54f462f4216fc591f29cb991610d9beb70d83bd9 | |
parent | ebcc4725d389f76be6a29c86856dbdbb3c719f5c (diff) | |
download | git-1db8f2ad61cb5d1fe42605f1a83e9d0d529e0731.tar.gz |
Return an enumerator when no block is given.
- I had apparently missed this lesson of being a good Ruby citizen over
the last twelve years or so. Regardless, it's a damned fine idea.
- Found in SamSaffron/mime-types at bdc7c442.
-rw-r--r-- | lib/mime/types.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/mime/types.rb b/lib/mime/types.rb index 01a7c34a0f..ae3f481292 100644 --- a/lib/mime/types.rb +++ b/lib/mime/types.rb @@ -97,7 +97,11 @@ class MIME::Types # Iterates through the type variants. def each - @type_variants.values.each { |tv| tv.each { |t| yield t } } + if block_given? + @type_variants.each_value { |tv| tv.each { |t| yield t } } + else + enum_for(:each) + end end @__types__ = nil @@ -237,7 +241,11 @@ class MIME::Types # MIME::Types#each against the default MIME::Types registry. def each - __types__.each {|t| yield t } + if block_given? + __types__.each {|t| yield t } + else + enum_for(:each) + end end # MIME::Types#type_for against the default MIME::Types registry. |