Created
April 11, 2010 23:15
-
-
Save undees/363136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Demo of YARD "duck typing" features; see http://yardoc.org | |
# | |
# Returns an Array containing two of everything in a collection | |
# (it need not be an Enumerable; it just has to have an #each method). | |
# | |
# @param [#each] collection items to double | |
# @return [Array] contains two of each item | |
# | |
def two_of_everything(collection) | |
result = [] | |
collection.each {|item| result += [item, item]} | |
result | |
end | |
two_of_everything [1, 'hello', true] # => [1, 1, "hello", "hello", true, true] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The somewhat stilted wording in “collection items to double” appears because YARD strips off the first word and uses it as the parameter name.