Chapter 6 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Variable scope examples

A

Local Var x =10
Global var $x = 10
Object(Instance) @x = 10, @side_length = side_length
Class Var @@x = 10

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

Classes:

A

A class is a collection of methods and data that are used as a blueprint to create multiple objects relating to that class.

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

Objects:

A

An object is a single instance of a class.

An object of class Person is a single person. An object of class Dog is a single dog. If you think of objects as real-life objects, a class is the classification, whereas an object is the actual object or “thing” itself.

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

Local variable:

A

A variable that can only be accessed and used from the current scope.

x = 10

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

Instance/object variable:

A

A variable that can be accessed and used from the scope of a single object. An object’s methods can all access that object’s object variables.

@side_length = side_length

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

Global variable:

A

A variable that can be accessed and used from anywhere within the current program.

$x = 10

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

Class variable:

A

A variable that can be accessed and used within the scope of a class and all of its child objects

@@number_of_squares

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

Encapsulation:

A

The concept of allowing methods to have differing degrees of visibility outside of their class or associated object.

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

Polymorphism:

A

The concept of methods being able to deal with different classes of data and offering a more generic implementation (as with the area and perimeter methods offered by your Square and Triangle classes).

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

Module:

A

An organizational element that collects together any number of classes, methods, and constants into a single namespace.

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

Namespace:

A

A named element of organization that keeps classes, methods, and constants from clashing.

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

Mix-in:

A

A module that can mix its methods in to a class to extend that class’s functionality.

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

Enumerable:

A

A mix-in module, provided as standard with Ruby, that implements iterators and list-related methods for other classes, such as collect, map, min, and max. Ruby uses this module by default with the Array and Hash classes.

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

Comparable:

A

A mix-in module, provided as standard with Ruby, that implements comparison operators (such as <, >, and ==) on classes that implement the generic comparison operator <=>.

To provide these methods, the Comparable module uses the <=> comparison operator on the class that includes it. <=> returns −1 if the supplied parameter is higher than the object’s value, 0 if they are equal, or 1 if the object’s value is higher than the parameter.

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

Class Method

A

class method is denoted with self., where self represents the current class, so def self.test_method defines the method as being specific to the class.

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

Super

A

looks up the inheritance chain and calls the method of the same name on the next highest class.

17
Q

Private

A

private tells Ruby that any methods declared in this class from there on should be kept private.

This means that only code within the object’s methods can access those private methods, whereas code outside of the class cannot.

18
Q

public

A

You could put private before one method, but then revert back to public methods again afterwards using public.

19
Q

Protected

A

protected that makes a method private, but within the scope of a class rather than within a single object.