Home / Interview / Ruby :: General Questions

Interview :: Ruby

21)

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.

22)

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.

23)

Explain retry statement in Ruby?

Ruby retry statement is used to repeat the whole loop iteration from the start.

24)

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:

25)

Explain Ruby object?

Object is the default root of all Ruby objects. Ruby objects inherit from BasicObject which allows creating alternate object hierarchies.

26)

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:

27)

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:

28)

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.

29)

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:

30)

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.