Ruby On Rails Interview Questions and Answers
Ques 11. How and when would you declare a Global Variable?
Ans. Global variables are declared with the $ symbol and can be declared and used anywhere within your program. You should use them sparingly to never.
Ques 12. How would you create getter and setter methods in Ruby?Ans. Setter and getter methods in Ruby are generated with the attr_accessor method. attr_accessor is used to generate instance variables for data thats not stored in your database column.
Ques 13. Describe the difference between class and instance variables?Ans.
Class variables are created with the prefix @@ and are shared by all objects in a class.
Instance variables are created with the prefix @ and belong to a single object within a class.
Ques 14. Example some of the looping structures available in Ruby?Ans. For loop, While loop, Until Loop.
Ques 15. Explain the difference between a has_one and belongs_to association in Ruby on Rails.Ans.
A product has_one provider, a customer has_one order.
Most helpful rated by users: