Ruby names Flashcards

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

Variables in Ruby can contain data of any type. You can use variables in your Ruby programs _____ ___ _______. Variable name itself denotes its scope (local, global, instance, etc.).

A

Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations. Variable name itself denotes its scope (local, global, instance, etc.).

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

A ____ variable (declared within an object) name consists of a lowercase letter (or an underscore) followed by name characters (sunil, _z, hit_and_run).

A

A local variable (declared within an object) name consists of a lowercase letter (or an underscore) followed by name characters (sunil, _z, hit_and_run).

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

An ______ variable (declared within an object always “belongs to” whatever object self refers to) name starts with an ‘‘at’’ sign (‘’@’’) followed by a name (@sign, @_, @Counter).

A

An instance variable (declared within an object always “belongs to” whatever object self refers to) name starts with an ‘‘at’’ sign (‘’@’’) followed by a name (@sign, @_, @Counter).

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

A ____ variable (declared within a class) name starts with two ‘‘at’’ signs (‘’@@’’) followed by a name(@@sign, @@_, @@Counter). A class variable is shared among all objects of a class. Only one copy of a particular class variable exists for a given class. Class variables used at the top level are defined inObject and behave like global variables. Class variables are rarely used in Ruby programs.

A

A class variable (declared within a class) name starts with two ‘‘at’’ signs (‘’@@’’) followed by a name(@@sign, @@_, @@Counter). A class variable is shared among all objects of a class. Only one copy of a particular class variable exists for a given class. Class variables used at the top level are defined inObject and behave like global variables. Class variables are rarely used in Ruby programs.

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

______ variables start with a dollar sign (‘’$’’) followed by name characters. A global variable name can be formed using ‘’$-‘’ followed by any single character ($counter, $COUNTER, $-x). Ruby defines a number of global variables that include other punctuation characters, such as $_ and $-K.

A

Global variables start with a dollar sign (‘’$’’) followed by name characters. A global variable name can be formed using ‘’$-‘’ followed by any single character ($counter, $COUNTER, $-x). Ruby defines a number of global variables that include other punctuation characters, such as $_ and $-K.

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

A _______ name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. Examples: module MyMath, PI=3.1416, class MyPune.

A

A constant name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. Examples: module MyMath, PI=3.1416, class MyPune.

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

_____ names should begin with a lowercase letter (or an underscore). “?”, “!” and “=” are the only weird characters allowed as method name suffixes (! or bang labels a method as dangerous-specifically, as the dangerous equivalent of a method with the same name but without the bang. More on Bang methods later.).

A

Method names should begin with a lowercase letter (or an underscore). “?”, “!” and “=” are the only weird characters allowed as method name suffixes (! or bang labels a method as dangerous-specifically, as the dangerous equivalent of a method with the same name but without the bang. More on Bang methods later.).

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

Ruby convention

A
The Ruby convention is to use underscores to separate words in a multiword method or variable name. By convention, most constants are written in all uppercase with underscores to separate words, LIKE\_THIS. Ruby class and module names are also constants, but they are conventionally written using initial capital letters and camel case, LikeThis.
It's to be noted that any given variable can at different times hold references to objects of many different types. A Ruby constant is also a reference to an object. Constants are created when they are first assigned to (normally in a class or module definition; they should not be defined in a method - more onconstants later). Ruby lets you alter the value of a constant, although this will generate a warning message. Also, variables in Ruby act as "references" to objects, which undergo automatic garbage collection.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Fixnum

A

that represents easily managed smaller numbers

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

Bignum

A

represents “big” numbers Ruby needs to manage internally.

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

The class _____ has a method called _____ that returns the class of an object, for example:

s = ‘hello’

s.class # String

A

The class Object has a method called class that returns the class of an object, for example:

s = ‘hello’

s.class # String

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