Ruby

[vc_row full_width=”stretch_row” css=”.vc_custom_1559286923229{background-color: #f6f6f7 !important;}”][vc_column width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”What is Ruby programming language?” tab_id=”1559286383409-ab730398-6c03″][vc_column_text]Ruby is a dynamic, reflective, general purpose, open source programming language that focuses on simplicity and productivity. Ruby has a mixed features of Perl, small talk, Eiffel, Ada and Lisp. Ruby was designed to create a new language which makes a balance with the functionality of Imperative languages.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Who is the developer of Ruby?” tab_id=”1559286522681-3bf94e12-e7b7″][vc_column_text]Ruby is designed and developed by Yukihiro “martz” Matsumoto in mid 1990 in Japan.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Why Ruby is known as a language of flexibility?” tab_id=”1561382593569-b1979b66-b066″][vc_column_text]Ruby is known as a language of flexibility because it facilitates its author to alter the programming elements. Some specific parts of the language can be removed or redefined. Ruby does not restrict the user. For example, to add two numbers, Ruby allows to use + sign or the word ‘plus’. This alteration can be done with Ruby’s built-in class Numeric.[/vc_column_text][/vc_tta_section][vc_tta_section title=”List some features of Ruby?” tab_id=”1561382595833-dd54d407-26c0″][vc_column_text]Ruby has many features. Some of them are listed below.

  • Object-oriented
  • Flexible
  • Dynamic typing and Duck typing
  • Garbage collector
  • Keyword arguments

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain some differences between Ruby and Python.” tab_id=”1561382597303-5168678c-55b9″][vc_column_text]Similarities:

  • High level language
  • Support multiple platforms
  • Use interactive prompt called irb
  • Server side scripting language

Differences:

  • Ruby is fully object oriented while Python is not.
  • Ruby supports EclipseIDE while Python supports multiple IDEs.
  • Ruby use Mixins while Python doesn’t.
  • Ruby supports blocks, procs and lambdas while Python doesn’t.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Write the command to get installed Ruby version in your system” tab_id=”1561382598718-1fee5a6b-29dd”][vc_column_text]ruby -v[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are class libraries in Ruby?” tab_id=”1561382602352-48d936eb-64df”][vc_column_text]Ruby class libraries contain variety of domain such as thread programming, data types, various domains. Following is a list of domains which has relevant class libraries:

  • Text processing
  • CGI Programming
  • Network programming
  • GUI programming
  • XML programming

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Name some operators used in Ruby.” tab_id=”1561382603416-a2e0c7df-e6f8″][vc_column_text]Operators are a symbol which is used to perform different operations.

  • Unary operator
  • Airthmetic operator
  • Bitwise operator
  • Logical operator
  • Ternary operator

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is RubyGems in Ruby programming language?” tab_id=”1561382604362-41fc1dd4-d143″][vc_column_text]RubyGems provides a standard format for distributing ruby programs and libraries. It works as a package manager for the Ruby programming language.

RubyGems is now a part of the standard library from Ruby version 1.9.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Ruby variables.” tab_id=”1561382605426-bedbe54f-bb01″][vc_column_text]Ruby variables hold data which can be used later in a program. Each variable act as a memory and shas a different name.

There are four types of variables in Ruby:

  • Local variable
  • Class variable
  • Instance variable
  • Global variable

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between nil and false in Ruby?” tab_id=”1561382606689-6de5471f-2224″][vc_column_text]

nil false
nil cannot be a value. false can be a value.
nil is returned where there is no predicate. in case of a predicate, true or false is returned by a method.
nil is not a boolean data type. false is a boolean data type.
nil is an object of nilclass. false is an object of falseclass.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby data types.” tab_id=”1561382593038-8e7f1218-a7ac”][vc_column_text]Ruby data types represent type of data such as text, string, numbers, etc.

There are different data types in Ruby:

  • Numbers
  • Strings
  • Symbols
  • Hashes
  • Arrays
  • Booleans

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of load and require in Ruby?” tab_id=”1561382592598-bfa5a635-55f4″][vc_column_text]In Ruby, load and require both are used for loading the available code into the current code. In cases where loading the code required every time when changed or every times someone hits the URL, it is suggested to use ‘load’.

It case of autoload, it is suggested to use ‘require’.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby if-else statement.” tab_id=”1561382592102-02f6742f-af9d”][vc_column_text]The Ruby if-else statement is used to test condition. There are various types of statement in Ruby.

  • if statement
  • if-else statement
  • if-else-if (elsif) statement
  • ternary statement

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain case statement in Ruby.” tab_id=”1561382591605-a59a34b3-da74″][vc_column_text]In Ruby, we use ‘case’ instead of ‘switch’ and ‘when’ instead of ‘case’. The case statement matches one statement with multiple conditions just like a switch statement in other languages.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain for loop in Ruby.” tab_id=”1561382591221-5a07bad8-cf1f”][vc_column_text]Ruby for loop iterates over a specific range of numbers. Hence, for loop is used if a program has fixed number of itrerations.

Ruby for loop will execute once for each element in expression.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain while loop in Ruby.” tab_id=”1561382590677-cc47cbcf-ee26″][vc_column_text]Ruby while loop is used to iterate a program several times. If the number of iterations is not fixed

for a program, while loop is used.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain do while loop in Ruby.” tab_id=”1561382590095-0dd9d5a4-e5bf”][vc_column_text]Ruby do while loop iterates a part of program several times. In this, loop will execute at least once because do while condition is written at the end.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain until loop in Ruby.” tab_id=”1561382589718-2e1a6ceb-a239″][vc_column_text]Ruby until loop runs until the given condition evaluates to true. It exits the loop when condition becomes true. It is opposite of the while loop.[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain break statement in Ruby.” tab_id=”1561382589333-47659694-5e1f”][vc_column_text]Ruby break statement is used to terminate a loop. It is mostly used in while loop where value is printed till the condition is true.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain next statement in Ruby.” tab_id=”1561382588926-dd3c13fa-09be”][vc_column_text]Ruby next statement is used to skip loop’s next iteration. Once the next statement is executed, no further iteration will be performed.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain redo statement in Ruby.” tab_id=”1561382588517-7fc83786-ee5a”][vc_column_text]Ruby redo statement is used to repeat the current iteration of the loop. The redo statement is executed without evaluating loop’s condition.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain retry statement in Ruby.” tab_id=”1561382588060-9c018b10-4231″][vc_column_text]Ruby retry statement is used to repeat the whole loop iteration from the start.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby object.” tab_id=”1561382587557-eee3186e-5475″][vc_column_text]Object is the default root of all Ruby objects. Ruby objects inherit from BasicObject which allows creating alternate object hierarchies.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to create Ruby object?” tab_id=”1561382583069-d03ea374-27b7″][vc_column_text]Objects in Ruby are created by calling new method of the class. It is a unique type of method and predefined in Ruby library.

Syntax:

  1. objectName=className.new

[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][vc_column width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”Explain Ruby class.” tab_id=”1561382561432-7f73ef2a-cc67″][vc_column_text]Each Ruby class is an instance of Ruby class. Classes in Ruby are first class objects. It always starts with a keyword class followed by the class name.

Syntax:

  1. class ClassName
  2. codes…

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Define Ruby methods.” tab_id=”1561382561455-654071d3-eb53″][vc_column_text]Ruby method prevent us from writing the same code in a program again and again. Ruby methods are similar to functions in other languages.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to use Ruby methods.” tab_id=”1561382611424-56181e07-6453″][vc_column_text]To use a Ruby method, we need to first define it. It is defined with def and end keyword.

Method name should always start with a lowercase letter.

Syntax:

  1. def methodName

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Ruby blocks.” tab_id=”1561382613753-7c9c9136-4ca1″][vc_column_text]Ruby code blocks are called closures in other programming languages. It consist of a group of codes which is always enclosed with braces or written between do…end.[/vc_column_text][/vc_tta_section][vc_tta_section title=”In how many ways a block is written in Ruby.” tab_id=”1561382614729-6b63842b-62b1″][vc_column_text]A block is written in two ways:

  • Multi-line between do and end
  • Inline between braces {}

Both are same and have the same functionality.

syntax:

  1. block_name{
  2. statement1
  3. statement2

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is yield statement in Ruby.” tab_id=”1561382615672-42dd66a8-6425″][vc_column_text]The yield statement is used to call a block within a method with a value.[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain ampersand parameter (&block) in Ruby.” tab_id=”1561382616984-e392adb7-34cd”][vc_column_text]The &block is a way to pass a reference (instead of a local variable) to the block to a method.

Here, block word after the & is just a name for the reference, any other name can be used instead of this.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby module.” tab_id=”1561382618152-4fb6fc3a-9883″][vc_column_text]Ruby module is a collection of methods and constants. A module method may be instance method or module method. They are similar to classes as they hold a collection of methods, class definitions, constants and other modules. They are defined like classes. Objects or subclasses can not be created using modules. There is no module hierarchy of inheritance.

Modules basically serve two purposes:

  • They act as namespace. They prevent the name clashes.
  • They allow the mixin facility to share functionality between classes.

Syntax:

  1. module ModuleName
  2. statement1
  3. statement2

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Explain module mixins in Ruby.” tab_id=”1561382619930-3767e1f0-f3d6″][vc_column_text]Ruby doesn’t support multiple inheritance. Modules eliminate the need of multiple inheritance using mixin in Ruby.

A module doesn’t have instances because it is not a class. However, a module can be included within a class.

When you include a module within a class, the class will have access to the methods of the module.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby strings.” tab_id=”1561382620762-261798c4-b2da”][vc_column_text]Ruby string object holds and manipulates an arbitary sequence of bytes, typically representing characters. They are created using String::new or as literals[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to access Ruby strings elements in an application.” tab_id=”1561382621738-44e10b8a-ca7d”][vc_column_text]You can access Ruby string elements in different parts with the help of square brackets []. Within square brackets write the index or string.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to write multiline string in Ruby.” tab_id=”1561382622978-99f18b2d-fe4d”][vc_column_text]Writing multiline string is very simple in Ruby language. We will show three ways to print multiline string.

  • String can be written within double quotes.
  • The % character is used and string is enclosed within / character.
  • In heredoc syntax, we use << and string is enclosed within word STRING.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the use of global variable $ in Ruby?” tab_id=”1561382623945-e109c4d3-ece0″][vc_column_text]The global variable is declared in Ruby that you can access it anywhere within the application because it has full scope in the application. The global variables are used in Ruby with $ prepend.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is concatenating string in Ruby. In how many ways you can create a concatenating string.” tab_id=”1561382625642-843354b1-1f56″][vc_column_text]Ruby concatenating string implies creating one string from multiple strings. You can join more than one string to form a single string by concatenating them.

There are four ways to concatenate Ruby strings into single string:

  • Using plus sign in between strings.
  • Using a single space in between strings.
  • Using << sign in between strings.
  • Using concat method in between strings.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are freezing string in Ruby.” tab_id=”1561382626563-0fa3f678-a5bf”][vc_column_text]In most programming languages strings are immutable. It means that an existing string can’t be modified, only a new string can be created out of them.

In Ruby, by default strings are not immutable. To make them immutable, freeze method can be used.[/vc_column_text][/vc_tta_section][vc_tta_section title=”In how many ways you can compare Ruby string?” tab_id=”1561382627658-bb4ddb6b-277e”][vc_column_text]Ruby strings can be compared with three operators:

  • With == operator : Returns true or false
  • With eql? Operator : Returns true or false
  • With casecmp method : Returns 0 if matched or 1 if not matched

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are class libraries in Ruby?” tab_id=”1561382628592-dd61fe2e-19d3″][vc_column_text]Ruby class libraries contain variety of domain such as thread programming, data types, various domains. Following is a list of domains which has relevant class libraries:

  • Text processing
  • CGI Programming
  • Network programming
  • GUI programming
  • XML programming

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Ruby arrays and how they can be created?” tab_id=”1561382630393-e350687e-823e”][vc_column_text]Ruby arrays are ordered collections of objects. They can hold objects like integer, number, hash, string, symbol or any other array.

Its indexing starts with 0. The negative index starts with -1 from the end of the array. For example, -1 indicates last element of the array and 0 indicates first element of the array.

A Ruby array is created in many ways.

  • Using literal constructor []
  • Using new class method

[/vc_column_text][/vc_tta_section][vc_tta_section title=”In how many ways items can be added in an array in Ruby?” tab_id=”1561382632977-3b296953-06eb”][vc_column_text]Ruby array elements can be added in different ways.

  • push or <<
  • unshift
  • insert

[/vc_column_text][/vc_tta_section][vc_tta_section title=”In how many ways items can be removed from array in Ruby?” tab_id=”1561382634764-ad5070ba-db90″][vc_column_text]Ruby array elements can be removed in different ways.

  • pop
  • shift
  • delete
  • uniq

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby hashes.” tab_id=”1561382636355-5dfe038c-83df”][vc_column_text]A Ruby hash is a collection of unique keys and their values. They are similar to arrays but array use integer as an index and hash use any object type. They are also called associative arrays, dictionaries or maps.

If a hash is accessed with a key that does not exist, the method will return nil.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to create a new time instance in Ruby?” tab_id=”1561382638762-3bfa136c-84a1″][vc_column_text]A new Time instance can be created with ::new. This will use your current system’s time. Parts of time like year, month, day, hour, minute, etc can also be passed.

While creating a new time instance, you need to pass at least a year. If only year is passed, then time will default to January 1 of that year at 00:00:00 with current system time zone.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain Ruby ranges. What are the ways to define ranges?” tab_id=”1561382649403-b75ce50f-0f5c”][vc_column_text]Ruby range represents a set of values with a beginning and an end. They can be constructed using s..e and s…e literals or with ::new.

The ranges which has .. in them, run from beginning to end inclusively. The ranges which has … in them, run exclusively the end value.

Ruby has a variety of ways to define ranges.

  • Ranges as sequences
  • Ranges as conditions
  • Ranges as intervals

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Ruby iterators?” tab_id=”1561382651188-733a0ad7-4f7c”][vc_column_text]Iterator is a concept used in object-oriented language. Iteration means doing one thing many times like a loop.

The loop method is the simplest iterator. They return all the elements from a collection, one after the other. Arrays and hashes come in the category of collection.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is sysread method in Ruby?” tab_id=”1561382674843-1f0b68aa-358c”][vc_column_text]The sysread method is also used to read the content of a file. With the help of this method you can open a file in any mode.[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][/vc_row][vc_row full_width=”stretch_row” overlay_color=”rgba(12,12,12,0.58)” css=”.vc_custom_1528340415800{padding-bottom: 104px !important;background-image: url(https://wordpresslms.thimpress.com/wp-content/uploads/sites/4/2017/06/layer-532.jpg?id=231) !important;background-position: center !important;background-repeat: no-repeat !important;background-size: cover !important;}” el_class=”overflow-visible become-teacher”][vc_column width=”1/2″][vc_column_text el_class=”align-right”]

Please login to send your request!
[/vc_column_text][/vc_column][vc_column width=”1/2″ el_class=”talk”][vc_column_text el_class=”thim-content-talk”]I’m a Copywriter in a Digital Agency, I was searching for courses that’ll help me broaden my skill set. Before signing up for Rob’s.[/vc_column_text][/vc_column][/vc_row]

WhatsApp us