Read the most frequently asked 26 top Ruby interview questions and answers for freshers and experienced.
Ruby Interview Questions and Answers PDF Experienced Freshers
1. Explain about ruby code blocks?
Ruby code blocks form an important part of ruby and are very fun to use. With the help of this feature you can place your code between do-end and you can associate them with method invocations and you can get an impression that they are like parameters. They may appear near to a source of the code and adjacent to a method call. The code is not executed during the program execution but it is executed when the context of its appearance is met or when it enters a method.
2. Explain about interpolation?
Interpolation is a very important process in Ruby. Interpolation is the process of inserting a string into a literal. There is only one way in which you can interpolate a string into a literal by placing a Hash (#) within {} open and close brackets. This refers to a new name to by referring to the copy of the original method.
3. Explain about Float, Dig and Max?
Float class is used whenever the function changes constantly. It acts as a sub class of numeric. They represent real characters by making use of the native architecture of the double precision floating point.
Max is used whenever there is a huge need of Float.
Dig is used whenever you want to represent a float in decimal digits.
4. How does ruby deal with extremely large numbers?
Unlike other programming languages ruby deals with extremely large numbers it doesn’t have any barriers. There is no limit on the extent of limit of number usage. Ruby performs this function with two different classes they are fixnum and bignum. Fixnum represents easily managed small numbers and bignum represents big numbers. Ruby entirely handles the functioning of these two classes which leaves a programmer to concentrate on his arithmetic operations.
5. Explain about Class variable and global variable?
A class variable starts with an @@ sign which is immediately followed by upper or lower case letter. You can also put some name characters after the letters which stand to be a pure optional. A class variable can be shared among all the objects of a class. A single copy of a class variable exists for each and every given class.
To write a global variable you start the variable with a $ sign which should be followed by a name character. Ruby defines a number of global variables which also include other punctuation characters such as $_ and $-k.
6. Explain about variables?
There are four different types of variables they are local, instance, global, and class. Variables can be used in the program without any declaration and they can contain data of any type. A local variable contains lower case characters followed by name characters. Instance variable starts with a @ sign followed by name characters.
7. Explain about ruby names?
Classes, variables, methods, constants and modules can be referred by ruby names. When you want to distinguish between various names you can specify that by the first character of the name. Some of the names are used as reserve words which should not be used for any other purpose. A name can be lowercase letter, upper case letter, number, or an underscore, make sure that you follow the name by name characters.
8. Explain about normal method class?
This function calls a method and it can take any number of arguments and expr. Make sure that you put an asterisk or an ampersand before the expression. Last expr argument can be declared with a hash without any braces. If you want to increase the size of the array value then make sure that you put an asterisk before expression. “::” can be used to separate the class from methods.
9. Explain about methods?
Methods in ruby basically perform two functions, named operation and the code present in the class which does a specific function. In Ruby all your algorithms live in methods which inturn is present on objects. Ruby does not have any provision for functions. Code present in Ruby is always a method of some object. Behind the scenes ruby gives you the flexibility to work with methods as functions if you are considering working with other languages.
10. Explain about the defined operator?
Define operator defines whether a passed expression is defined or not. If the expression is defined it returns the description string or null if the expression is not defined. If a variable is defined it gets initialized. If method_call is defined as true then method also gets defined. This is also the same case with super and yield.
11. Explain about operators in Ruby?
Like all the modern languages Ruby supports many different operators to its credit. Most of the operators in Ruby are in fact methods due to the object oriented nature of the language. This feature gives Ruby an edge over its competitors. Semantics of these operators can be changed due to the object oriented nature of the language.
12. Explain about environment variables present in ruby?
Following are some of the environment variables used to control the behavior programming of ruby. While programming ENV object lists some of the current variables. RUBYLIB path searches for libraries. Make sure that you separate each path with colons. RUBYOPT passes command line options to Ruby interpreter. There are many more which can be obtained by searching the huge pool of library.
13. Explain about the command line options?
Ruby`s language is executed from the command line like most of the scripting languages. Programming and behavior language environment can be controlled from the interpreter itself. Some of the commands which are used are as follows –d, -h, -e prog, -v, -T, -r lib, etc.
14. Explain about garbage collection feature of ruby?
Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program. Ruby deletes unallocated and unused objects automatically. This feature can be controlled by applying proper syntax and program through ruby.
15. Explain about portability?
Ruby language can be ported to many platforms. Ruby programs can be ported to many platforms without any modification to the source code. This feature made the language very useful and highly used by many programmers worldwide. Some of the platforms used are DOS, UNIX, WINDOWS, etc.
16. Explain about class libraries in ruby?
Ruby has a strong set of class libraries and it covers from a variety of domains such as thread programming, domains and data types. Also ruby is a new language and it also has additional libraries coming every day. Many of the new languages which do exist have huge libraries because of their age.
17. Explain about the programming language ruby?
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.
18. What is Rails?
? Ruby on Rails is an open source web application framework for the Ruby programming language.
? It is used with an Agile development methodology that is used by web developers for rapid development.
19. Describe class libraries in Ruby.
? The Ruby standard library extends the foundation of the Ruby built-in library with classes and abstractions for a variety of programming needs, including network programming, operating system services, threads, and more.
? These classes provide flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains.
20. Explain the concepts and capabilities of garbage collection feature of Ruby.
? Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program.
? Ruby deletes unallocated and unused objects automatically.
? This feature can be controlled by applying proper syntax and program through ruby.
21. Describe the environment variables present in Ruby.
RUBYOPT
Additional command-line options to Ruby; examined after real command-line options are parsed ($SAFE must be 0).
RUBYLIB
Additional search path for Ruby programs ($SAFE must be 0).
RUBYPATH
With -S option, search path for Ruby programs (defaults to PATH).
RUBYSHELL
Shell to use when spawning a process; if not set, will also check SHELL or COMSPEC. DLN_LIBRARY_PATH Search path for dynamically loaded modules.
RUBYLIB_PREFIX
(Windows only) Mangle the RUBYLIB search path by adding this prefix to each component.
22. Interpolation is a very important process in Ruby, comment.
? Interpolation is the process of inserting a string into a literal.
? You can interpolate a string into a literal by placing a Hash (#) within {} open and close brackets.
? This refers to a new name to by referring to the copy of the original method.
23. What is the use of super in Ruby Rails?
? Ruby uses the super keyword to call the superclass implementation of the current method.
? Within the body of a method, calls to super acts just like a call to that original method.
? The search for a method body starts in the superclass of the object that was found to contain the original method.
def url=(addr)
super (addr.blank? || addr.starts_with?('http')) ? addr : http://#{addr}
end
24. What is the use of load and require in ruby?
Reuire() loads and processes the Ruby code from a separate file, including whatever classes, modules, methods, and constants are in that file into the current scope.
Load() performs the inclusion operation once, it reprocesses the code every time load is called.
25. Explain the use of global variable $ in Ruby?
If you declare one variable as global we can access any where, where as class variable visibility only in the class
26. Explain the difference between nil and false in ruby?
False is a boolean datatype
Nil is not a data type
Ruby Interview Questions and Answers PDF Experienced Freshers
1. Explain about ruby code blocks?
Ruby code blocks form an important part of ruby and are very fun to use. With the help of this feature you can place your code between do-end and you can associate them with method invocations and you can get an impression that they are like parameters. They may appear near to a source of the code and adjacent to a method call. The code is not executed during the program execution but it is executed when the context of its appearance is met or when it enters a method.
2. Explain about interpolation?
Interpolation is a very important process in Ruby. Interpolation is the process of inserting a string into a literal. There is only one way in which you can interpolate a string into a literal by placing a Hash (#) within {} open and close brackets. This refers to a new name to by referring to the copy of the original method.
3. Explain about Float, Dig and Max?
Float class is used whenever the function changes constantly. It acts as a sub class of numeric. They represent real characters by making use of the native architecture of the double precision floating point.
Max is used whenever there is a huge need of Float.
Dig is used whenever you want to represent a float in decimal digits.
4. How does ruby deal with extremely large numbers?
Unlike other programming languages ruby deals with extremely large numbers it doesn’t have any barriers. There is no limit on the extent of limit of number usage. Ruby performs this function with two different classes they are fixnum and bignum. Fixnum represents easily managed small numbers and bignum represents big numbers. Ruby entirely handles the functioning of these two classes which leaves a programmer to concentrate on his arithmetic operations.
5. Explain about Class variable and global variable?
A class variable starts with an @@ sign which is immediately followed by upper or lower case letter. You can also put some name characters after the letters which stand to be a pure optional. A class variable can be shared among all the objects of a class. A single copy of a class variable exists for each and every given class.
To write a global variable you start the variable with a $ sign which should be followed by a name character. Ruby defines a number of global variables which also include other punctuation characters such as $_ and $-k.
6. Explain about variables?
There are four different types of variables they are local, instance, global, and class. Variables can be used in the program without any declaration and they can contain data of any type. A local variable contains lower case characters followed by name characters. Instance variable starts with a @ sign followed by name characters.
7. Explain about ruby names?
Classes, variables, methods, constants and modules can be referred by ruby names. When you want to distinguish between various names you can specify that by the first character of the name. Some of the names are used as reserve words which should not be used for any other purpose. A name can be lowercase letter, upper case letter, number, or an underscore, make sure that you follow the name by name characters.
8. Explain about normal method class?
This function calls a method and it can take any number of arguments and expr. Make sure that you put an asterisk or an ampersand before the expression. Last expr argument can be declared with a hash without any braces. If you want to increase the size of the array value then make sure that you put an asterisk before expression. “::” can be used to separate the class from methods.
9. Explain about methods?
Methods in ruby basically perform two functions, named operation and the code present in the class which does a specific function. In Ruby all your algorithms live in methods which inturn is present on objects. Ruby does not have any provision for functions. Code present in Ruby is always a method of some object. Behind the scenes ruby gives you the flexibility to work with methods as functions if you are considering working with other languages.
10. Explain about the defined operator?
Define operator defines whether a passed expression is defined or not. If the expression is defined it returns the description string or null if the expression is not defined. If a variable is defined it gets initialized. If method_call is defined as true then method also gets defined. This is also the same case with super and yield.
11. Explain about operators in Ruby?
Like all the modern languages Ruby supports many different operators to its credit. Most of the operators in Ruby are in fact methods due to the object oriented nature of the language. This feature gives Ruby an edge over its competitors. Semantics of these operators can be changed due to the object oriented nature of the language.
12. Explain about environment variables present in ruby?
Following are some of the environment variables used to control the behavior programming of ruby. While programming ENV object lists some of the current variables. RUBYLIB path searches for libraries. Make sure that you separate each path with colons. RUBYOPT passes command line options to Ruby interpreter. There are many more which can be obtained by searching the huge pool of library.
13. Explain about the command line options?
Ruby`s language is executed from the command line like most of the scripting languages. Programming and behavior language environment can be controlled from the interpreter itself. Some of the commands which are used are as follows –d, -h, -e prog, -v, -T, -r lib, etc.
14. Explain about garbage collection feature of ruby?
Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program. Ruby deletes unallocated and unused objects automatically. This feature can be controlled by applying proper syntax and program through ruby.
15. Explain about portability?
Ruby language can be ported to many platforms. Ruby programs can be ported to many platforms without any modification to the source code. This feature made the language very useful and highly used by many programmers worldwide. Some of the platforms used are DOS, UNIX, WINDOWS, etc.
16. Explain about class libraries in ruby?
Ruby has a strong set of class libraries and it covers from a variety of domains such as thread programming, domains and data types. Also ruby is a new language and it also has additional libraries coming every day. Many of the new languages which do exist have huge libraries because of their age.
17. Explain about the programming language ruby?
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.
18. What is Rails?
? Ruby on Rails is an open source web application framework for the Ruby programming language.
? It is used with an Agile development methodology that is used by web developers for rapid development.
19. Describe class libraries in Ruby.
? The Ruby standard library extends the foundation of the Ruby built-in library with classes and abstractions for a variety of programming needs, including network programming, operating system services, threads, and more.
? These classes provide flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains.
20. Explain the concepts and capabilities of garbage collection feature of Ruby.
? Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program.
? Ruby deletes unallocated and unused objects automatically.
? This feature can be controlled by applying proper syntax and program through ruby.
21. Describe the environment variables present in Ruby.
RUBYOPT
Additional command-line options to Ruby; examined after real command-line options are parsed ($SAFE must be 0).
RUBYLIB
Additional search path for Ruby programs ($SAFE must be 0).
RUBYPATH
With -S option, search path for Ruby programs (defaults to PATH).
RUBYSHELL
Shell to use when spawning a process; if not set, will also check SHELL or COMSPEC. DLN_LIBRARY_PATH Search path for dynamically loaded modules.
RUBYLIB_PREFIX
(Windows only) Mangle the RUBYLIB search path by adding this prefix to each component.
22. Interpolation is a very important process in Ruby, comment.
? Interpolation is the process of inserting a string into a literal.
? You can interpolate a string into a literal by placing a Hash (#) within {} open and close brackets.
? This refers to a new name to by referring to the copy of the original method.
23. What is the use of super in Ruby Rails?
? Ruby uses the super keyword to call the superclass implementation of the current method.
? Within the body of a method, calls to super acts just like a call to that original method.
? The search for a method body starts in the superclass of the object that was found to contain the original method.
def url=(addr)
super (addr.blank? || addr.starts_with?('http')) ? addr : http://#{addr}
end
24. What is the use of load and require in ruby?
Reuire() loads and processes the Ruby code from a separate file, including whatever classes, modules, methods, and constants are in that file into the current scope.
Load() performs the inclusion operation once, it reprocesses the code every time load is called.
25. Explain the use of global variable $ in Ruby?
If you declare one variable as global we can access any where, where as class variable visibility only in the class
26. Explain the difference between nil and false in ruby?
False is a boolean datatype
Nil is not a data type
0 comments:
Post a Comment