ROR Questions Flashcards

1
Q

Rails CRUD

A

Create, Read, Update, Destroy //routes.rb resources :articles

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

WHAT IS EAGER LOADING?

A

Eager loading is a great optimization strategy to reduce the number of queries that are made against the DB. clients = Client.includes(:address).limit(10) clients.each do |client| puts client.address.postcode end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a class? How and When to create?

A

A class is the blueprint from which individual objects are created. class Customer end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an object?

A

Is an instance of the class. You can create objects in Ruby by using the method new of the class. cust1 = Customer.new The initialize method is a special type of method, which will be executed when the new method of the class is called with parameters def initialize(id, name, addr) @cust_id=id @cust_name=name @cust_addr=addr end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you declare and use a constructor in Ruby?

A

Constructors are declared via the initialize method and get called when you call on a new object to be created. Order.new class Order def initialize(meal) @meal = meal end end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When to use a symbol?

A

Used as keys in Hashes. Used on attr_accessor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you create getter and setter methods in Ruby?

A

Setter and getter methods in Ruby are generated with the attr_accessor method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is polymorphic association?

A

With polymorphic associations, a model can belong to more than one other model, on a single association.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Proc?

A

short for procedures, act similar to blocks, but can be saved as variables and reused. Think of them as blocks you can call over and over again on multiple arrays. square = Proc.new do |n| n ** 2 end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Block?

A

a block is like a proc that can’t be saved. array = [1, 2, 3, 4] array.collect! do |n| n ** 2 end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are lambdas?

A

Anonymous function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between a class and a module?

A

A module cannot be subclassed or instantiated, and modules can implement mixins.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three levels of method access control for classes and what do they signify? What do they imply about the method?

A

Public methods can be called by all objects and subclasses of the class in which they are defined in. Methods are public by default except for initialize, which is always private.

A protected method can be invoked only by objects of the defining class and its subclasses. Access is kept within the family.

Private methods cannot be accessed, or even viewed from outside the class. Only the class methods can access private members.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain what functional testing is:

A

Functional testing in Rails allows you to test the response of various actions contained in a controller.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The initialize method:

A

class Box

def initialize(w,h)

@width, @height = w, h

end

end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Class Inheritance:

A

Inheritance allows us to define a class in terms of another class.

existing class is called the base class or superclass.

new class is referred to as the derived class or sub-class.

eg:

ArticlesController

ApplicationController

17
Q

Methods Overriding:

A

You can do so simply by keeping the method name same and overriding the functionality of the parent class method.

18
Q

Abstraction

A

The abstraction is simplifying complex reality by modeling classes appropriate to the problem.

19
Q

Encapsulation

A

hides the implementation details of a class from other objects.

20
Q

What is the constructor?

A

The purpose of the constructor is to initiate the state of an object. The constructor in Ruby is called initialize. Constructors do not return any values.

class Being

def initialize

puts “Being is created”

end

end

Being.new