ClosureCowboy
ClosureCowboy

Reputation: 21541

Naming convention (or a term) for parameters that could represent either a collection or a single item

My particular case deals with Ruby, though it could apply to almost any language.

I've been using noun_or_nouns to name parameters that could represent either a collection or a single item. For example: action_or_actions, favorite_sidewalk_or_sidewalks

Is there a less awkward naming convention? Is there a single word to describe objects that could be a collection or a single item? I've mainly dealt with C++ and C#, and this sort of thing rarely comes up in either of those languages.

I'm looking for something self-documenting, so that callers of the method know that either a collection or a single item are acceptable.

Upvotes: 2

Views: 78

Answers (1)

Tyler Holien
Tyler Holien

Reputation: 4951

I would just use the plural name and drop the singular. Is there ever a time you would treat it any differently, even if there's only one item?

names.each do |name|
    #do something with the name
end

Upvotes: 3

Related Questions