Top 40 Ruby Interview Questions
Q1. What Is The Use Of Load And Require In Ruby?
In Ruby, load and require each are used for loading the available code into the modern code. In instances wherein loading the code required whenever while changed or each instances someone hits the URL, it's far suggested to apply 'load'. It case of autoload, it's far suggested to apply 'require'.
Q2. Mention What Is The Command To Create A Migration?
To create migration command consists of
C:rubyapplication>ruby script/generate migration table_name
Q3. How Would You Create Getter And Setter Methods In Ruby?
Setter and getter strategies in Ruby are generated with the attr_accessor approach. Attr_accessor is used to generate instance variables for statistics that’s no longer saved to your database column.
You can also take the lengthy route and create them manually.
Q4. Explain About The Defined Operator?
Define operator defines whether a handed expression is described or now not. If the expression is described it returns the outline string or null if the expression isn't always described. If a variable is described it gets initialized. If method_call is described as genuine then method also gets described. This is likewise the equal case with extraordinary and yield.
Q5. Explain About Garbage Collection Feature Of Ruby?
Garbage series is a technique of reclaiming the memory area. Ruby deletes unallocated and unused objects robotically. This feature can be managed by using making use of proper syntax and software via ruby.
Ruby performs garbage series routinely. Ruby is an object orientated language and every item orientated language has a tendency to allocate many gadgets in the course of execution of this system.
Q6. Explain About Ruby Names?
Classes, variables, techniques, constants and modules can be referred through ruby names. When you need to distinguish among diverse names you may specify that by means of the first character of the call. Some of the names are used as reserve phrases which need to now not be used for another cause. A call can be lowercase letter, higher case letter, range, or an underscore, ensure which you observe the name by way of call characters.
Q7. Overview Of Ruby Programming Language?
Ruby is a dynamic, open supply programming language. It focuses on productiveness and ease. The syntax is elegant that is natural to study and easy to write down and use. The language is flexible, since it allows the developers alter freely all its components. At will, you'll put off vital elements and redefined. For instance , the symbol + may be redefined by using the phrase ‘plus’ to one of the its lessons – Numeric.
Ruby supports multiple programming paradigms, consisting of, practical, vital, object oriented, relative. Dynamic reminiscence management and dynamic type structures are extra functions of Ruby.
Q8. Explain The Use Of Global Variable $ In Ruby?
If you declare one variable as international we can get admission to any in which, where as class variable visibility simplest inside the magnificence
Q9. What Is The Use Of Super In Ruby Rails?
The feature excellent is used to invoke the authentic technique, looking of the method body starts offevolved in the notable elegance of the object that changed into found to comprise the original technique. The following instance depicts the identical.
Def url=(cope with)
extremely good (address.Clean deal with.Starts_with?('http')) ? Deal with : http://#cope with
end
Q10. Explain The Difference Between Nil And False In Ruby.
The variations of the methods nil and fake are:
nil can't be a value, wherein as a fake can be a cost.
A method returns real or fake in case of a predicate, different wise nil is returned.
Fake is a boolean statistics kind, wherein as nil isn't.
Nil is an item for NilClass, wherein as fake is an object of for FalseClass
Q11. Mention What Is The Difference Between A Single Quote And Double Quote?
A single-quoted strings don’t procedure ASCII get away codes, and they don’t do string interpolation.
Q12. Explain About Methods?
Methods in ruby basically perform features, named operation and the code present within the elegance which does a specific feature. In Ruby all your algorithms stay in techniques which inturn is present on gadgets. Ruby does not have any provision for capabilities. Code found in Ruby is continually a technique of some object. Behind the scenes ruby gives you the flexibility to work with methods as features in case you are considering running with different languages.
Q13. Why Ruby Is Known As A Language Of Flexibility?
Ruby is called a language of flexibility because it helps its writer to modify the programming elements. Some precise parts of the language may be removed or redefined. Ruby does not limit the person. For example, to feature two numbers, Ruby lets in to apply + sign or the phrase 'plus'. This alteration can be executed with Ruby's built-in magnificence Numeric.
Q14. Explain About Normal Method Class?
This function calls a way and it can take any variety of arguments and expr. Make sure which you positioned an asterisk or an ampersand earlier than the expression. Last expr argument can be declared with a hash with none braces. If you need to growth the size of the array price then make sure that you placed an asterisk before expression. “::” may be used to split the class from strategies.
Q15. What Is The Difference Between A Class And A Module?
A module cannot be subclassed or instantiated, and modules can enforce mixins.
Q16. Explain Some Of The Looping Structures Available In Ruby?
For loop, While loop, Until Loop.
Q17. How Does A Symbol Differ From A String?
Symbols are immutable and reusable, maintaining the same object_id.
Be organized to talk about the benefits of the use of symbols vs. Strings, the effect on reminiscence utilization, and in which situations you will use one over the opposite.
Q18. Describe Class Libraries In Ruby?
Ruby elegance libraries incorporate of type of domain names, consisting of thread programming, information sorts, diverse domain names. It has extra libraries evolving daily. The following are the domain names which has relevant magnificence libraries.
Text processing - File, String, Regexp for brief and smooth textual content processing.
CGI Programming - There are assisting elegance library for CGI programming guide like, facts base interface, eRuby, mod_ruby for Apache, textual content processing instructions.
Network programming – Various well-designed sockets are to be had in ruby for network programming.
GUI programming – Ruby/Tk and Ruby/Gtk are the lessons for GUI programming
XML programming – UTF-8 text processing normal expression engine make XML programming very reachable in ruby. .
Q19. What Is The Use Of Interpolation In Ruby?
Interpolation is a system of inserting a string into a literal. It is a totally essential procedure in Ruby. A string may be interpolated right into a literal via putting a hash (#) inside open and close brackets.
Q20. What Is Rubygems In Ruby Programming Language?
RubyGems offers a preferred layout for dispensing ruby programs and libraries. It works as a package supervisor for the Ruby programming language. RubyGems is now a part of the usual library from Ruby version 1.9.
Q21. Explain About Float, Dig And Max?
Float class is used whenever the feature adjustments constantly. It acts as a sub magnificence of numeric. They represent actual characters by utilizing the local structure of the double precision floating point.
Max is used each time there's a massive want of Float.
Dig is used whenever you need to symbolize a float in decimal digits.
Q22. What Are The Different Environment Variables Present In The Ruby?
Following are the extraordinary surroundings variables present within the Ruby:
RUBYOPT
RUBYLIB
RUBYPATH
RUBYSHELL
RUBYLIB_PREFIX
Q23. Mention What Is The Difference Between Procs And Blocks?
The difference between Procs and Blocks,
Block is simply the a part of the syntax of a way whilst proc has the traits of a block.
Procs are items, blocks aren't.
At most one block can appear in a controversy listing.
Only block isn't always capable of be stored right into a variable whilst Proc can.
Q24. Explain About Class Variable And Global Variable?
A magnificence variable starts offevolved with an @@ sign which is immediately observed by means of top or decrease case letter. You also can placed some call characters after the letters which stand to be a natural optionally available. A elegance variable can be shared amongst all the gadgets of a class. A single replica of a category variable exists for each and each given class.
To write a international variable you start the variable with a $ sign which ought to be accompanied by means of a name man or woman. Ruby defines a number of global variables which additionally encompass different punctuation characters along with $_ and $-ok.
Q25. Interpolation Is A Very Important Process In Ruby, Comment?
Inserting a string into a literal is referred to as as interpolation. Interpolation is a completely crucial manner in Ruby. Interpolation may be accomplished by means of the use of simplest one manner with the aid of embedding # inside . A new name is mentioned the replica of the original call.
Q26. Explain About Operators In Ruby?
Like all of the modern-day languages Ruby supports many different operators to its credit score. Most of the operators in Ruby are in fact strategies due to the item oriented nature of the language. This feature gives Ruby an area over its competitors. Semantics of these operators may be changed due to the item orientated nature of the language.
Q27. What Is Ruby Programming Language?
Ruby is a dynamic, reflective, widespread motive, open source programming language that makes a speciality of simplicity and productiveness. Ruby has a mixed capabilities of Perl, small communicate, Eiffel, Ada and Lisp. Ruby become designed to create a new language which makes a balance with the functionality of Imperative languages.
Q28. How Does Ruby Deal With Extremely Large Numbers?
Unlike different programming languages ruby offers with extraordinarily big numbers it doesn’t have any boundaries. There is not any limit at the quantity of restrict of wide variety utilization. Ruby plays this feature with two exclusive classes they may be fixnum and bignum. Fixnum represents without problems managed small numbers and bignum represents large numbers. Ruby completely handles the functioning of those training which leaves a programmer to concentrate on his mathematics operations.
Q29. Explain About Ruby Code Blocks?
Ruby code blocks form an crucial a part of ruby and are very amusing to use. With the help of this feature you can location your code among do-quit and you can accomplice them with method invocations and you can get an influence that they're like parameters. They may additionally seem near to a supply of the code and adjoining to a way call. The code isn't always carried out in the course of this system execution however it's far performed when the context of its look is met or while it enters a technique.
Q30. Explain About The Command Line Options?
Ruby`s language is completed from the command line like most of the scripting languages. Programming and behavior language environment may be controlled from the interpreter itself. Some of the instructions which are used are as follows –d, -h, -e prog, -v, -T, -r lib, etc.
Q31. Explain About Interpolation?
Interpolation is a very essential procedure in Ruby. Interpolation is the procedure of placing a string right into a literal. There is most effective one way in which you could interpolate a string into a literal via setting a Hash (#) inside open and near brackets. This refers to a new call to by referring to the copy of the unique technique.
Q32. List Out The Few Features Of Ruby?
Free layout – You can begin writing from program from any line and column.
Case touchy – The uppercase and lowercase letters are wonderful.
Comments – Anything followed by an unquoted #, to the cease of the road on which it seems, is unnoticed by the interpreter.
Statement delimiters- Multiple statements on one line have to be separated via semicolons, however they're no longer required at the quit of a line.
Q33. What Is Rails?
Ruby on Rails is an internet software framework. It is written in Ruby. Compare to different frameworks for web application, the large deal is the way Ruby on Rails does. A web application finished in days in place of weeks, it's far noticed by way of the network. Maintenance and/or extension of messy and tough web applications is flexible with ruby rails.
Q34. Explain How Can We Define Ruby Regular Expressions?
Ruby everyday expression is a special sequence of characters that enables you in shape or find other strings. A normal expression literal is a sample among arbitrary delimiters or slashes observed through %r.
Q35. Mention What Is The Difference Between A Gem And A Plugin In Ruby?
Gem: A gem is a just ruby code. It is set up on a gadget, and it’s available for all ruby programs strolling on that system.
Plugin: Plugin is also ruby code, but it's miles installed in the software folder and simplest available for that specific application.
Q36. Explain The Difference Between Nil And False In Ruby?
False is a boolean datatype
Nil isn't always a records type
Q37. Explain About Variables?
There are 4 specific styles of variables they may be neighborhood, instance, global, and sophistication. Variables may be used within the software without any assertion and they could contain information of any kind. A nearby variable includes lower case characters accompanied by way of name characters. Instance variable starts offevolved with a @ sign followed by call characters.
Q38. What Is The Use Of Global Variable $ In Ruby?
The global variable is declared in Ruby that you can get admission to it anywhere inside the software as it has complete scope in the utility. The global variables are used in Ruby with $ prepend.
Q39. What Are The Three Levels Of Method Access Control For Classes And What Do They Signify? What Do They Imply About The Method?
Public, covered, and personal.
Public strategies can be called through all gadgets and subclasses of the magnificence wherein they're defined in.
Protected techniques are handiest handy to objects inside the equal class.
Private techniques are only handy within the equal example.
Q40. Explain About Portability?
Ruby language can be ported to many systems. Ruby applications can be ported to many systems without any modification to the supply code. This characteristic made the language very useful and fantastically utilized by many programmers global. Some of the platforms used are DOS, UNIX, WINDOWS, and so on.

