Can any one please explain the below simple statement
@object ||= ::Tablename.where (:fieldname => value ).first
What is it mean and why || is used with = and :: is used before table name ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The snippet checks to see if
@objectisfalseornil; if it is, it assigns it the value produced by calling the method namedTablenamein the top-level namespace.This is because
||=means “assign if the value is currently falsey”; and::is the scope resolution operator. Often it appears with a class name on the left, as inNet::HTTPaccessing theHTTPconstant in theNetmodule. Without a name on the left, it means “in the top-level scope”.