Arnaud J. wrote:
line_items << li
So far, I know that has_many adds several methods, such as line_items<<
I also know that, inside a method, an assignment to some "var" without
"self." before it might confuse ruby which can take "var" for a local
variable. So using self.var is "safer".
But here, there's no "self.line_items << li". Why does calling
"line_items <<" is enough for this piece of code to understand that
line_items isn't a mere variable ?
"self" is not needed here because the line is not an assignment
(no "="). Unlike an assignment, for the line to have any meaning
line_items must have been defined previously, so the interpreter
sees no ambiguity.