JOBSEEKER?

Ruby Interview Questions

Practice for Ruby interviews by solving TestDome questions. Our interview questions are used by more than 7,000 companies and 450,000 individual test takers.

Jobseekers: Certify Your Knowledge

Take a Certification Test

Companies: Use Our Tests for Screening

Buy a Pack Of Candidates

Need to practice your Ruby programming skills for an upcoming job interview? Try solving these Ruby interview questions that test knowledge of arrays, closures, functions, and other skills. We’ll provide feedback on your answers, and you can use a hint if you get stuck.

These Ruby interview questions are examples of real tasks used by employers to screen job candidates such as Ruby developers, back-end developers, full-stack developers, and others that require knowledge of the Ruby programming language and its native data structures and language constructs.

1. Merge Names

Easy  
Ruby Arrays Public

Implement the unique_names method. When passed two arrays of names, it will return an array containing the names that appear in either or both arrays. The returned array should have no duplicates.

For example, calling unique_names(["Ava", "Emma", "Olivia"], ["Olivia", "Sophia", "Emma"]) should return an array containing Ava, Emma, Olivia, and Sophia in any order.

Solve Question

2. Quadratic Equation

Easy 
Ruby Arithmetic New Public

Implement the function find_roots to find the roots of the quadratic equation: ax2 + bx + c = 0. The function should return an array containing both roots in any order. If the equation has only one solution, the function should return that solution as both elements of the array. The equation will always have at least one solution.

The roots of the quadratic equation can be found with the following formula: A quadratic equation.

For example, find_roots(2, 10, 8) should return [-1, -4] or [-4, -1] as the roots of the equation 2x2 + 10x + 8 = 0 are -1 and -4.

Solve Question

3. File Owners

Easy  
Ruby Hash 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']}.

Solve Question

4. Pipeline

Hard  
Ruby Closures Higher Order Function Public

As part of a data processing pipeline, complete the implementation of the pipeline method:

  • The method should accept a variable number of functions, and it should return a new function that accepts one parameter arg.
  • The returned function should call the first function in the pipeline with the parameter arg, and call the second function with the result of the first function.
  • The returned function should continue calling each function in the pipeline in order, following the same pattern, and return the value from the last function.

For example, pipeline(-> (x) { x * 3 }, -> (x) { x + 1 }, -> (x) { x / 2 }) then calling the returned function with 3 should return 5.

Solve Question

5. Student Records

Hard  
Ruby Lambda Functions Splats Public

Implement the filter method. It should accept a list of students and a variable number of filters. The filters will be passed in as lambdas, each of which will take one student record and return a boolean value.

filter should return a list of student records that have passed through all the filters.

If no filters are provided, the list of student records should be returned as is. If no students pass through all the provided filters (or if no students are provided), return an empty array.

For example, consider the following code:

students = [
  { name: 'Thomas Edison', gpa: 3.45 },
  { name: 'Grace Hopper', gpa: 3.99 },
  { name: 'Leonardo DaVinci', gpa: 2.78 }
]

honor_roll = ->(record) { record[:gpa] > 3.0 }

filter(students, honor_roll) should return:

[{:name=>"Thomas Edison", :gpa=>3.45},{:name=>"Grace Hopper", :gpa=>3.99}]
Solve Question

If you feel ready, take one of our timed public Ruby Interview Questions tests:
Ruby

Ruby Online Test (Easy / Hard)

Ruby and SQL Online Test (Easy / Hard)

Ruby on Rails Online Test (Easy / Hard)

HTML/CSS

HTML/CSS, JavaScript, Ruby, and SQL Online Test (Easy / Hard)

Not exactly what you are looking for? Go to our For Jobseekers section.
Dashboard Start Trial Sign In Home Tour Tests Questions Pricing For Jobseekers