Ruby interview questions

Want to become an expert in cracking Ruby interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public Ruby interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. ContactsMigration
Ruby Database migrations Ruby on Rails Public

Select all statements that are correct after the following migration has been executed:

class ContactsMigration < ActiveRecord::Migration
  def change
    create_table :contacts do |t|
      t.string :name
      t.text :address
      t.integer :tnumber
    end

    rename_column :contacts, :tnumber, :telephone_number
    add_timestamps(:contacts, null: true)
  end
end
Easy  
3min
Solve question

2. EmployeeSearch
Ruby Database abstraction Ruby on Rails Public

A company database contains the following table, in which id is the primary key:

employees
idnameage
1Steve21
2John44
3Amy26
4Marcus44

Select all the statements that return the employee with name "John" (id = 2).

Easy  
3min
Solve question

3. FileOwners
Ruby Language Public

Implement a group_by_owners function that:

  • Accepts a hash containing the file owner name for each file name.
  • Returns a hash containing an array of file names for each owner name, in any order.

For example, for hash {'Input.txt' => 'Randy', 'Code.py' => 'Stan', 'Output.txt' => 'Randy'} the group_by_owners function should return {'Randy' => ['Input.txt', 'Output.txt'], 'Stan' => ['Code.py']}.

Easy  
15min
Solve question

4. Palindrome
Ruby Strings Public

A palindrome is a word that reads the same backward or forward.

Write a function that checks if a given word is a palindrome. Character case should be ignored.

For example, is_palindrome("Deleveled") should return true as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.

Easy  
10min
Solve question

5. Path
Ruby Data structures Strings Public

Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example:

path = Path.new('/a/b/c/d')
puts path.cd('../x').current_path

should display '/a/b/c/x'.

Note: Do not use built-in path-related functions.

Hard  
30min
Solve question

If you feel ready, take one of our timed public Ruby interview questions tests:

  • HTML/CSS, JavaScript, Ruby, and SQL online test (Easy / Hard)
  • Ruby online test (Easy)
  • Ruby and SQL online test (Easy / Hard)
  • Ruby on Rails online test (Easy)
Not exactly what you are looking for? Go to our For developers section.