Skip to content

Instantly share code, notes, and snippets.

@undees
Created April 11, 2010 23:15
Show Gist options
  • Save undees/363136 to your computer and use it in GitHub Desktop.
Save undees/363136 to your computer and use it in GitHub Desktop.
# 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]
@undees
Copy link
Author

undees commented Apr 11, 2010

The somewhat stilted wording in “collection items to double” appears because YARD strips off the first word and uses it as the parameter name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment