Interview Prep Flashcards
What standard seven restful actions for
resources :photos
Describe a class, an object, a module, and why we need them?
Classes are constructs that create instances of themselves and enables instances to have state and behavior. Objects are instances of class. Modules are a collection of methods and constants.
What are the three levels of method access control for classes?
The three levels of access are Public, Protected, and Private.
Public methods can be called by all object and subclasses and are enforced by no access control. Protected methods are only accessible to objects within the same class. Private methods are only accessible within the same instance.
What does self mean?
Self always refers to the current object. However, classes are also objects in Ruby. A candidate that notes that should get bonus points.
Describe functional testing.
In Rails, functional testing lets you test the response of various actions contained in a controller. The programmer should understand that the functional test will tell their testing library to expect certain responses based on control requests.
Always have the programmer program.
Knowing textbook answers for questions is one thing. Being able to execute Ruby-On-Rails is another. You always want to set up real world tests for your candidates. For a beginner position, have the candidate perform actions such as creating and setting up a Rails environment or using migration to manage a database.
Intermediate candidates should be able to perform actions such as setting up and deploying a Rails app for production.
Experienced candidates should be able to analyze current applications for things such as performance, memory, and security issues. Additionally they should model databases and analyze queries.
There is an abundance of self-proclaimed Ruby-On-Rails experts out there. Sifting through the pros and amateurs will take time but will prove worthwhile in the end.
what is the naming convention in Rails?
Variables: For declaring Variables, all letters are lowercase, and words are separated by underscores
Class and Module: Modules and Classes uses MixedCase and have no underscore; each word starts with a uppercase letter
Database Table: The database table name should have lowercase letters and underscore between words, and all table names should be in the plural form for example invoice_items
Model: It is represented by unbroken MixedCase and always have singular with the table name
Controller: Controller class names are represented in plural form, such that OrdersController would be the controller for the order table.
Explain what is “Yield” in Ruby on Rail?
A Ruby method that receives a code block invokes it by calling it with the “Yield”.
Explain what is ORM (Object-Relationship-Model) in Rails?
ORM or Object Relationship Model in Rails indicate that your classes are mapped to the table in the database, and objects are directly mapped to the rows in the table.
Mention what the difference is between false and nil in Ruby?
In Ruby False indicates a Boolean datatype, while Nil is not a data type, it have an object_id 4
Explain what is the role of sub-directory app/controllers and app/helpers?
App/controllers: A web request from the user is handled by the Controller. The controller sub-directory is where Rail looks to find controller classes
App/helpers: The helper’s sub-directory holds any helper classes used to assist the view, model and controller classes.
what is the difference between String and Symbol?
They both act in the same way only they differ in their behaviors which are opposite to each other. The difference lies in the object_id, memory and process tune when they are used together. Symbol belongs to the category of immutable objects whereas Strings are considered as mutable objects.
Explain how Symbol is different from variables?
Symbol is different from variables in following aspects
- It is more like a string than variable
- In Ruby string is mutable but a Symbol is immutable
- Only one copy of the symbol requires to be created
- Symbols are often used as the corresponding to enums in Ruby
Explain what is Rails Active Record in Ruby on Rail?
Rails active record is the Object/Relational Mapping (ORM) layer supplied with rails. It follows the standard ORM model as
- Table map to classes
- Rows map to objects
- Columns map to object attributes
how you can create a controller for subject?
Command Line:
- ruby generate controller subject