1.How is visibility of methods changed in Ruby (Encapsulation)?
A.By applying the access modifier : Public , Private and Protected access Modifier.
2.What are ruby gems?
A. A gem is nothing more than a piece of ruby code packaged as a library so that it can be imported and used by others in their programs.
3.What is the difference between a Symbol and String?
A.Symbols and string are used interchangeably by various developers and their usage within gems can be confusing at times. You can think of Symbols as faster & immutable strings. Once a string is used up it is marked for cleaning by the garbage collector but it is not cleaned up immediately and it cannot be reused.
4.What is the purpose of yield?
A.The interpreter essentially invokes a separate piece of code and places it in the location. You might say it is similar to a method calling another method. Let�s understand a little bit of background about where yield might be useful first.
5.What are class variables? How do you define them?
A.Class variables are created using the @@ prefix to denote the variable as class level. It works just like any other variable, however in the case of inheritance it works more like a static variable that is accessed across all variable instances.
6.How do you define instance variables?
A.Instance variables are defined using single @ symbol. They are defined as : @foo = "Hello"
7.How do you define global variables?
A.Global variables are defined using single $ symbol. They are defined as : $foo = 5
8.Does Ruby support constructors? How are they declared?
A.Constructors are supported in Ruby. They are declared as the method initialize, shown below. The initialize method gets called automatically when Album.new is called.
9.How can you dynamically define a method body?
A.An instance method can be defined dynamically with Module#define_method(name, body), where name is the methods name given as a Symbol, and body is its body given as a Proc, Method, UnboundMethod, or block literal.
10.What is a Range?
A.Range is a great way to declare continuous variables. You should use it to declare arrays and other types of collections.
11.How can you implement method overloading?
A.In the case of Ruby method overloading is not supported. However, it does support the overall goal of passing variable number of parameters to the same method.
12.What is the difference between "&&", "and" and "&" operators?
A.The "&&" and "and" are both logical and statements. They "&&" operator has higher precedence though.
13.How can you create setter and getter methods in Ruby?
A.The setter and getter methods can be created manually by the developer or it can be auto-generated by Ruby.
14.What is the convention for using "!" at the end of a method name?
A.The ! indicates that the method is about to change the object itself.
15.What is a module?
A.A module is like a class. Except that it can�t be instantiated or subclassed. In OOP paradigm you would store methods & variables that represent variables in a single class. Say you want to create an Employee representation then the employee�s name, age, salary, etc. would all go inside a Employee class, in a file called Employee.rb
16.Does Ruby support multiple inheritance?
A.Ruby does not support multiple inheritance.
17.How can you achieve the same effect as multiple inheritance using Ruby? What is mixin?
A.Ruby offers a very neat alternative concept called mixin. Modules can be imported inside other class using mixin. They are then mixed-in with the class in which they are imported.
18.How will you implement a singleton pattern?
A.Singleton means single instance. So, the goal of a singleton pattern is to write a class definition but only allow the creation of the single instance of that object.
19.What is the default access modifier (public/protected/private) for a method?
A.By default all methods are public, except the initialize(constructor) method.
20.How can you call the base class method from inside of its overridden method?
A.If you are inside the overridden method in the derived class then a simple call to super will call the right method in the base class.
21.Define the Rails MVC implementation?
A.The MVC framework is an age-old architecture pattern that works very well for most applications. Rails has adopted the MVC pattern in its inherent design.
22.What is scope? (or named_scope in Rails 2.x).
A.Scopes are nothing more than SQL scope fragments. By using these fragments one can cut down on having to write long queries each time you access content.
23.Can you give an example of a class that should be inside the lib folder?
A.Modules are often placed in the lib folder.
24.Where should you put code that is supposed to run when your application launches?
A.In the rare event that your application needs to run some code before Rails itself is loaded, put it above the call to require "rails/all" in config/application.rb.
25.What deployment tool do you use?
A.Capistrano is a popular deployment tool.
26.How can you migrate your database schema one level down?
A.The rake tool does most of the migrations. Migration is done like this : "rake db:migrate"
27.What is a sweeper?
A.Sometimes you want to have control over how often and when the cache expires. Sometimes it is a good idea to have the system determine that on a logical basis. Say you have a list of product on your site and you want to reload the cache each time a new product is added/updated/deleted, then you can achieve this by using the sweeper.
28.How can you implement caching in Rails?
A.ails offers multiple ways to cache content. Fragment caching is my favorite because it gives you the choice to fragment to pull a portion from the cache and the remaining from a real-time DB call. Say you wanted to show all the orders placed on your website in real time and didn�t want to cache that part of the page, but did want to cache the part of the page which lists all products available
29.What is a filter?
A.Filters are methods that are called either before/after a controller action is called.
30.What do controllers do in Rails?
A.Once a request comes into the Rails stack, it goes to the routes table to determine which controller and action should be called. Once a controller action is determined the request is routed to the controller and it does the needed processing by connecting with the DB if needed and then it sends control to the View to render the output.
33.What is the purpose of layouts?
A.Layouts are partial ruby/html files that are used to render the content pages. There are placed in the folder: app/views/layouts Items that you would typically put in this folder are things like headers/footers, navigation elements, etc.
34.Is it possible to embed partial views inside layouts? How?
A.That is the purpose of layouts. You embed partial views inside the file /app/views/layout/application.html.erb and then whenever you render any page this layout is merged with it.
35.What is Rake?
A.Rake is a popular ruby gem that makes the job of running tasks simpler. Rake is most often used for DB tasks, but it can be used for m The common DB commands are: rake db:migrate and rake db:reset
36.What is Capistrano?
A.Capistrano is a popular deployment tool � it allows developers to push code from their desktop to the servers.
37.What is the difference between has_one and belongs_to?
A.A has_one relationship is used to define a 1:1 relationship between two objects. A belongs_to relationship on the other hand is used to define the reverse association for the same 1:1 relationship that is defined using the has_one keyword.
38.What is a polymorophic association?
A.A polymorphic association is what one would call �open-ended� association of one class with multiple objects.
39.What is eager loading?
A.Eager loading is a great optimization strategy to reduce the number of queries that are made against the DB.
40.How does validation work?
A.Validation means checking to see if data is good before it is stored in the database. During signups and other such user input cases you want to check and be sure that the data is validated. In the past developers would often put this type of validation logic as triggers in the database. In an MVC architecture one can do validations at each level. You can do validations in the controllers but it is usually a good idea to keep your controllers skinny.
41.How can you add a custom validation on your model?
A.Now custom validations takes it to the next step. Say you want to confirm that the data meets certain criteria .
42.What is flash?
A.Flash is simply a way to pass some value to the next action. Anything you place in the flash will be exposed to the very next action and then cleared out.
43.How can you install the missing gems that are required by your application in the simplest way?
A."bundle install" : This command will install all dependencies and missing gems. It looks at your Gemfile to figure out what gems are needed by your application.
44.How can you implement internationalization?
A.Ruby ships with i18n which is an internationalization gem. You need to create locale files and save them under the config/locales directory as: en.yml , es.yml and fr.yml
45.What plugin would you recommend for user authentication and authorization?
A.Devise works great with Rails. It supports OAuth authentication and therefore integrates nicely with Facebook.
46.What plugin do you use for full-text search?
A.Sunspot supports full-text search capability and uses Solr as the back-end search engine to do so.
47.What is the difference between a plugin and a gem?
A.A gem is just ruby code. It is installed on a machine and it�s available for all ruby applications running on that machine. Rails, rake, json, rspec � are all examples of gems. Plugin is also ruby code but it is installed in the application folder and only available for that specific application.
48.How can you show search user friendly urls instead of using only numeric ids?
A.The simplest way to do this is to use the gem FriendlyID. It gives you the ability to specify a friendly URL for pages so that instead of the standard page URLs like: http://mysite.com/page/1
49.How can you create page titles and metadata for your pages?
A.You can use the Headliner plugin for adding page titles. You can use the MetaMagic plugin to add meta tags.
50.How can you create breadcrumbs on your pages?
A.Gretel is a great plugin to introduce breadcrumbs in your Rails application. Another very simple implementation is breadcrumb_on_rails.
51.Is Rails scalable?
A.Yes Rails gives you complete freedom to use all traditional means of scaling an application. Things like memcached, caching full pages, caching fragments are all supported.
52.How can you safeguard a rails application from SQL injection attack?
A.Rails already has the logic built into it to prevent SQL injection attacks if you follow the right syntax.
53.How can you secure a rails application?
A.Rails has a lot of in-built capabilities to deal with common web-security issues. Like : SQL Injection, Cross-Site , Session fixation and Session hijacking, Captcha
54.Can you tell me a few good community resources for Rails?
A.Stackoverflow, Github, various Meetup groups.
55.Where would you reach out to get the community to answer your questions?
A.Stackoverflow and meetup groups.
56.In which Programming language was Ruby written?
A.Ruby was written in C language and Ruby on Rails written in Ruby
57.How many types of relationships does a Model has?
A.has_one, belongs_to, has_many and has_many :through
58.What is Ruby Gems?
A.Ruby Gem is a software package, commonly called a "gem". Gem contains a packaged Ruby application or library. The Ruby Gems software itself allows you to easily download, install and manipulate gems on your system.
59.What is Session and Cookies?
A.Session is used to store user information on the server side where as Cookies are used to store the information in the client side.
60.What is the basic difference between GET and POST method?
A.GET is basically for just getting (retrieving) the data, whereas POST may used to do multiple things, like storing or updating data, or ordering a product, or sending E-mail etc.
61.What id the difference between Static and Dynamic Scaffolding?
A.The Syntax of Static Scaffold is like this: ruby script/generate scaffold Home New Where New is the model and Home is your controller, In this way static scaffold takes two parameter i.e your controller name and model name, whereas in dynamic scaffolding you have to define controller and model one by one.
62.What is ORM Rails ?
A.ORM stands for Object-Relationship-Model, it means that your Classes are mapped to table in the database and Objects are directly mapped to the rows in the table.
63.Does Ruby supports Multiple Inheritance?
A.No, Ruby supports only single Inheritance.
64.What is the difference between puts and print ?
A."puts" appends a new line and outputs each argument to a new line but print doesnt append anything and seems to separate arguments by a space.
65.What are the servers supported by ruby on rails?
A.Ruby Supports a number of Rails servers (Mongrel, WEBRICK, PHUSION, Passenger, etc..depending on the specific platforms). For each Rails application project, RubyMine provides default Rails run/debug configurations for the production and development environments.
66. Can we use two databases into a single application?
A.Yes, Definitely. magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time.
67.What is scope?
A. Scopes are nothing more than SQL scope fragments. By using these fragments one can cut down on having to write long queries each time you access content.
68.What deployment tool do you use?
A.Capistrano is a popular deployment tool, it allows developers to push code from their desktop to the servers. you can also use chef as a deployment tool for your project.
69.What is request.xhr?
A.A request.xhr tells the controller that the new Ajax request has come, It always return TRUE or FALSE.
70.How to serialize data with YAML?
A.YAML is a straight forward machine parsable data serialization format, designed for human readability and interaction with scripting language such as Perl and Python. YAML is optimized for data serialization, formatted dumping, configuration files, log files, internet messaging and filtering.
71.What is Active Record?
A.Active Record are like Object Relational Mapping(ORM), where classes are mapped to table and objects are mapped to colums in the table.
72.What is Mixin ?
A.Ruby does not suppoprt mutiple inheritance directly but Ruby Modules have another, wonderful use. At a stroke, they pretty much eliminate the need for multiple inheritance, providing a facility called a mixin. Mixins give you a wonderfully controlled way of adding functionality to classes.
73.What is purpose of RJs in Rails ?
74.What is an observer?
A.Observer serves as a connection point between models and some other subsystem whose functionality is used by some of other classes, such as email notification. It is loose coupling in contract with model callback.
75.What is a sweeper in rails?
A.Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change. They do this by being half-observers, half-filters and implementing callbacks for both roles. You can get more Informations here.
76.How can you list all routes for an application?
A.By writing rake routes in the terminal we can list out all routes in an application.
77. Is it possible to embed partial views inside layouts? How?
A.Yes it is possible. You Embed partial views inside the file /app/views/layout/application.html.erb and then whenever you render any page this layout is merged with it.
78.What is rake?
A.rake is command line utility of rails. �Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility �make�, and uses a �Rakefile� and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.�
79.What is Rails?
A.Rails is a extremely productive web-application framework written in Ruby language by David Hansson.Rails are an open source Ruby framework for developing database-backend web applications.Rails include everything needed to create a database-driven web application using the Model-View-Controller (MVC) pattern.
80.Explain about RESTful Architecture.
A.RESTful: REST stands for Representational State Transfer. REST is an architecture for designing both web applications and application programming interfaces (API�s), that�s uses HTTP. RESTful interface means clean URLs, less code, CRUD interface. CRUD means Create-READ-UPDATE-DESTROY. In REST, they add 2 new verbs, i.e, PUT, DELETE.
81.What is meant by action pack?
A.Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The �VC� part of �MVC�.
82.What is meant by action support?
A.Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
83.What do you mean by render?
A.render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.
84.What do you mean by redirect_to?
A.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.
85.What are helpers and how to use helpers in ROR?
A.Helpers are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view.
86.What is meant by Action Controller?
A.Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.
87.what is meant by Action View?
88.What is meant by Action View?
A.Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default.
89.What is meant by Action Dispatch?
A.Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.
90.What is meant by action mailer?
A.Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
91.What is meant by Active Model?
A.Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.
92.What is meant by Active Record?
A.Active Record: Active Record are like Object Relational Mapping (ORM), where classes are mapped to table, objects are mapped to columns and object attributes are mapped to data in the table.
93.What is meant by Active Resource?
A.Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.
94.How to use two databases into a single application?
A.magic multi-connections allows you to write your model once, and use them for the multiple rails databases at the same time. sudo gem install magic_multi_connection. After installing this gem, just add this line at bottom of your environment.rb require �magic_multi_connection�
95.What are the various changes between the Rails Version 2 and 3?
A. Introduction of bundler (new way to manage your gem dependencies), Gemfile and Gemfile.lock (where all your gem dependencies lies, instead of environment.rb) and HTML5 support.
96.What is TDD and BDD?
A.TDD stands for Test-Driven-Development and BDD stands for Behavior-Driven-Development.
97.What do you mean by Naming Convention in Rails?
A.Variables,Class and Module,Database Table,Model and Controller are naming convention in rails.
98.What is the log that has to seen to check for an error in ruby rails?
A.Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.
99.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
100.How you run your Rails application without creating databases?
A.You can run your application by uncommenting the line in environment.rb path=> rootpath conf/environment.rb config.frameworks- = [action_web_service, :action_mailer, :active_record
101.Ruby Supports Single Inheritence/Multiple Inheritence or Both?
A.Ruby Supports only Single Inheritnece.
102.What is bundler?
A.Bundler is a new concept introduced in Rails3, which helps to you manage your gems for the application. After specifying gems in your Gemfile, you need to do a bundle install. If the gem is available in the system, bundle will use that else it will pick up from the rubygems.org.
103.What is the Newest approach for find(:all) in Rails 3?
A. Model.where(:activated => true).
104.What is has_many?
A. It is a way of defining relationships among models. Correct, and Do you guys really know has_many is also an example of Meta-programming? Wondering, How?
105.Explain about the programming language ruby?
A.Ruby is the brain child of a Japanese programmer Matz. He created Ruby. It is a cross platform object oriented language. It helps you in knowing what your code does in your application. With legacy code it gives you the power of administration and organization tasks. Being open source, it did go into great lengths of development.
106.What is the Difference between Symbol and String?
A. Symbol are same like string but both behaviors is different based on object_id, memory and process time (cpu time) Strings are mutable , Symbols are immutable.
107.Whats the difference in scope for these two variables: @name and @@name?
A.@name is an instance variable and @@name is a class variable
108.Where does the start_tabnav gets informations for tabs rendering in ruby rail?
A. The main Symbol let the start_tabnav method know to look for a special MainTabnav class where all the magic happens.
109.What is the Install rail package?
A.There are several packages that you can download and install. The prebuilt Rails installer called Install rail which currently is only for Windows.
110.What is the use of super in ruby rails?
A.Ruby uses the super keyword to call the superclass (Parent class) implementation of the current method.
111.What is the difference between nil and false in ruby?
A.False is a boolean datatype, Nil is not a data type it have object_id 4 .
112.What are the priority of operators available in Ruby ?
A. Something that used in an expression to manipulate objects such as + (plus), - (minus), * (multiply), and / (divide). You can also use operators to do comparisons,such as with <, >, and &&. The priority is based on "BODMAS"
113.What are the object-oriented programming features supported by Ruby and how multiple inheritance supported in ?
A.Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and overloading) are some oo concepts supported by ruby. Multiple inheritance supported using Mixin concept.