0% found this document useful (0 votes)
133 views

ROR Questions

The document summarizes a technical interview for a Ruby on Rails position. It includes questions about SQL, Ruby language features, Rails frameworks, HTTP/REST, software design principles, and JavaScript. The interview consists of 32 questions covering topics such as database queries, Ruby concepts like classes and metaprogramming, ActiveRecord associations, HTTP verbs and status codes, REST API design, SOLID principles, and JavaScript functions.

Uploaded by

Sarmad Tabassum
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

ROR Questions

The document summarizes a technical interview for a Ruby on Rails position. It includes questions about SQL, Ruby language features, Rails frameworks, HTTP/REST, software design principles, and JavaScript. The interview consists of 32 questions covering topics such as database queries, Ruby concepts like classes and metaprogramming, ActiveRecord associations, HTTP verbs and status codes, REST API design, SOLID principles, and JavaScript functions.

Uploaded by

Sarmad Tabassum
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

RoR Technical Interview Candidate: Date:

v. 1.1 Interviewer: Time:

N Questions and Answers Interviewer Notes

SQL

You have the following data structure:

Q1 Show all primary keys and foreign keys

A1

Q2 Write down SQL which will find first user (ordered by ID) user whose name starts with ‘A’

A2 Select * from users order by id where name LIKE ‘A%’ limit 1;

Q3 Write down SQL query which will find all documents for a user with email “[email protected]

A3 Select * from documents inner join access ON documanets.id = access.documanet_id INNER JOIN users
ON access.user_id = users.idwhere users.email = ““[email protected]

Page 1 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

Q4 Write down SQL query which will calculate for every user number of documents he has an access. Find
below an example of expected output. The result of your query should look like the following:
Name Email Number Of Documents
Accessed

John Doe [email protected] 10

Jane Doe [email protected] 5

Jake Doe [email protected] 0

A4 select users.name,users.email, count(users.id) from users inner join access ON users.id = access.user_id
group by users.name, users.email;

Q5 What are normalization and denormalization? What are “pros and contras” of each? In what practical
cases will you use each of them?

A5

Ruby Language

Q6 What is the difference between include and extend? Write snippets of code which demonstrates the
difference?

A6

Q7 What are the differences between proc and lambda?

A7

Q8 What is the difference between fail, raise and throw?

Page 2 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

A8

Q9 What’s the meaning of amperssent (&) operation? Describe all use cases you know.

A9

Q10 What is a singleton class in Ruby? How one can extend it?

A10

Q11 You have an object x of cass MyClass and you call its method foo (x.foo). Where Ruby runtime will look
for this method implementation?

A11

Q12 What is “monkey patching” technique? What are “pros and contras”. In which practical cases would you
use it?

A12

Q13 Write a method str_to_h which will take a string and convert it to a hash where the keys are indexes of the
character and the values are characters. For instance:
str_to_h(“Hello”) => { 0: ‘H’, 1: ‘e’, 2: ‘l’, 3: ‘l’, 4: ‘o’ }

A13 Def str_to_h(str)


str.to_h

Q14 Write a method reverse_chain which will take a string name replace each word with its length and returns
the reversed array of length. Not that words could be separated by more than one space. For instance:
reverse_chain(“I want to work at Pair Finance ”) => [7, 4, 2, 4, 2, 4, 1]

Page 3 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

A14

Rails Framework

Q15 What is the difference between a includes and joins in ActiveRecord

A15

Q16 What the problem with the code below? How will you fix ti?

Company.all.each { |c| c.users.each { |u| puts “#{c.name} #{user.name}” } }

A16

Q17 How would you define a Person model so that any Person can be assigned as the parent of another
Person (as demonstrated in the Rails console below)? What columns would you need to define in the
migration creating the table for Person?

john = Person.create(name: "John")


jim = Person.create(name: "Jim", parent: john)
bob = Person.create(name: "Bob", parent: john)
john.children.map(&:name)
=> ["Jim", "Bob"]

A17 has_one :parent, class: Person


has_many :children, class: Person

Page 4 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

Q18 Update the Person model so that you can also get a list of all of a person’s grandchildren, as illustrated
below. Would you need to make any changes to the corresponding table in the database?

sally = Person.create(name: "Sally")


sue = Person.create(name: "Sue", parent: sally)
kate = Person.create(name: "Kate", parent: sally)
lisa = Person.create(name: "Lisa", parent: sue)
robin = Person.create(name: "Robin", parent: kate)
donna = Person.create(name: "Donna", parent: kate)
sally.grandchildren.map(&:name)
=> ["Lisa", "Robin", "Donna"]

A18 has_many :grandchildren, through: children, class: Person

Q19 What is a ActiveSupport::Concern? How and when are you using it?

A19

Imagine you have the following controllers inheritance structure:

Page 5 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

Q20 AdminsController has the following method

def hello
render ‘greetings’
end

Where Rais will look for greetings view? (Give list of folders’ paths)

A20 Base > users > admins

Q21 Consider the controllers hierarchy above. If session ended in general you want to redirect to application
login page (login_path), but for AdminsController you want to redirect to special admin login page
(admin_loing_path). How can you do it?

A21

Q22 Consider the controllers hierarchy above. You want to have specific layouts for all views in
UsersController and AdminsController. How can you do it?

A22

HTTP and REST

Q23 What's the difference between POST and GET verbs? When one should use each?

Page 6 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

A23

Q24 What's the difference between POST, PUT and PATCH verbs? When one should use each?

A24

Q26 What are other verbs do you now? How are they used?

A26

Q28 What does Content-Type header serve for?

A28

Q29 What content types do you know for HTTP requests and responses?

A29

Q30 What other headers do you know? How are they used?

A30

Page 7 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

Q31 List all HTTP response status code series and explain their meaning.

A31

Q32 What is REST API? What are “must haves” of the goor designed REST API on your opinion?

A32

Software Design

Q33 How do you understand DRY (don’t repeat yourself) principle? Why is it important?

A33

Q34 How do you understand SOLID (Single responsibility, Open–closed, Liskov substitution, Interface
segregation and Dependency inversion) principle?

A34

Q35 What design patterns do you know? (Give 3-5 examples).

A35

Page 8 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

JavaScript

Q36 What will the following code output?

(function() {
var a = b = 5;
})();

console.log(b);

A36 skip

Q37 Write a function that would allow you to do this.

multiply(5)(6); => 30

A37

Q38 How would you add your own method to the Array object so the following code would work?

var arr = [1, 2, 3, 4, 5];


var avg = arr.average();
console.log(avg);

A38 Function average(){


Arr = [1, 2, 3, 4, 5]
for(i=0, i+=1, i<10){
a= a+arr[i]
}

Page 9 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

Q39 What is a Closure and How do you use it? Give examples.

A39

Q40 What happens when you call a function with the new keyword?

A40

Q41 What is the difference between the classical and the prototypical inheritance?

A41

Q42 After an object is created, for example using the new keyword, how can we access the prototype object
that the instantiated object is linked to?

A42

Q43 You have an object x = { a: 1, b: 2, c: 3 } and you have a variable with name of one properties y=’b’.
Get the values of property x.b using only variables x and y.

A43

Page 10 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

CSS

Q44 Explain what elements will match each of the following CSS selectors:

div, p
div p
div > p
div + p
div ~ p

A44

Q45 You are given a CSS rule:


#a div > .c a.d{ color: red; }

Describe in plain eglish which elements will browser select to apply red text color.

A45

Q46 How do margin, border and padding fit together in the box model?

Page 11 of 12
RoR Technical Interview Candidate: Date:
v. 1.1 Interviewer: Time:

U
2
Applic A D UsersCo
1 1 2
Base
i i i Admins
Contr
d d d Controll
4
oller *u * 1ti er 3
n

A46

Page 12 of 12

You might also like