Thursday, August 30, 2012

Ruby Handbook (Frequently Used Concepts)

Frequently used concepts-
1. Difference between 'do..end' block and brackets { }.
Ans: Do End Block vs. Brackets

2. Copying Ruby object.
Ans: All variables in ruby are references to an object. a = b means that a and b points to the same object. To copy an object use a = b.dup . Credit

3. What is Ruby's double-colon (::) ?
Ans. Double color :: in Ruby

4. How to call Class Methods from Instance Methods? Difference between Class Methods and Instance Methods? Also the differences between class instances and method instances.
Ans: Using Modules and mixins. A mixin is a module, but a module isn't necessarily a mixin.
        a. Difference between class variables and instance variables
        b. Difference between class methods and instance methods

5. Ruby is not a statically typed language i.e. it is a dynamic language and there is no such thing called compile time check. That's why even if there is some conflict in accessing a method because of its Access Protection then it will be determined only at runtime without any prior warning.

6. In Ruby, all variable are references to objects not their copies.

7. What is the difference between puts and print method?
Ans: puts method add a new line character after each print however print method does not. So if you have a block to print all elements of  an array, then puts method will list each object of array in new line however puts will place all elements in single line like a string. Other references

8. Name a method which is used to get next int or character from a variable? i.e. to get 3 from a variable whose value is 2 or to get B from a variable A.
Ans: <variable>.succ (Successor)

9. Difference between Single Quote and Double Quotes in Ruby?
Ans: Mostly single quotes are used when we don't need to have string "interplation", where actually we use double quotes. Single Quote Vs Double Quote (Brief)

10. What are Exit codes in Ruby?
Ans: Whenever you run a Ruby script/program, a process is started. When a process is completed or interrupted in middle, it always exits with a exit code within range 0-255 which represents whether process was successful or not. An exit code with 0 means that program was successful. More details: Exit code in ruby

11. What is Database migration and list all methods used for the same
Ans. Migrations are a convenient way for you to alter your database in a structured and organized manner. Complete explanation: Migrations in ruby on rails

12. RubyMine - Could not find gem "jquery-rails". or similar gems
Ans. In such issues, run command gem install jquery-rails from the command line. Stackoverflow Adding a new gem

13. Scope of instance variable in a controller method. How long it will be retained?
Ans: 

No comments:

Post a Comment