Reputation: 1689
I know that macros like has_many
in Rails use pluralization. What i wasnt able to find is a reason for that behavior. If I have a class Number
, i'd write has_many :numbers
, but where is the benefit of it? I mean, im talking about a program, not a poem.
Does 'number' state "Im ref to a scalar" and' numbers' state "Im an array"…?
From what i've seen in the sourecode of has_many, im not shure where the translation from plural to singular occures and if it is possible to instead use a different approach for my own code. Is it possible to have ActiveRecord just use singular forms or – lets say – pluralize to §singular to mark a collection without breaking string.pluralize capabillity?
Upvotes: 1
Views: 587
Reputation: 14973
Ruby, and by extension Rails strive to be programmer friendly. An important part of that is having human readable code, therefore Rails developers have made it so that you would have a plural name where plain English calls for a plural.
It also helps to distinguish between a single object and a collection of objects, at first glance. Makes it a lot easier to read somebody else's code.
Upvotes: 2
Reputation: 2880
It is a simple linguistic cue as to whether you are dealing with a collection or a single instance. It just removes much mental churn as you don't have to consciously think about collection vs. instance.
Upvotes: 2