Interview :: Ruby
Explain next statement in Ruby?
Ruby next statement is used to skip loop's next iteration. Once the next statement is executed, no further iteration will be performed.
Explain redo statement in Ruby?
Ruby redo statement is used to repeat the current iteration of the loop. The redo statement is executed without evaluating loop's condition.
Explain retry statement in Ruby?
Ruby retry statement is used to repeat the whole loop iteration from the start.
How will you comment in Ruby?
Ruby comments are non-executable lines in a program. They do not take part in the execution of a program.
Single line comment syntax:
Multi line comment syntax:
Explain Ruby object?
Object is the default root of all Ruby objects. Ruby objects inherit from BasicObject which allows creating alternate object hierarchies.
How to create Ruby object?
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:
Explain Ruby class?
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:
Define Ruby methods?
Ruby method prevent us from writing the same code in a program again and again. Ruby methods are similar to functions in other languages.
How to use Ruby methods?
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:
What are Ruby blocks?
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.