Ruby Flashcards

1
Q

alias

alias :newname :oldname

A

Creates an alias/ second name for the method.

Thus, method defined for newname and oldname are

the same.

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

BEGIN

BEGIN {

` some code `

}

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

begin

begin

` #some code `

rescue

` #some code `

ensure

` #some code `

end

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

module

A

Creates an interface/helper that allows code to

from the module to be executed in any

other ruby files that require

the module.

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

next

A

Jumps to the next iteration in the

most internal loop.

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

case

case number

when 0...3

` some code`

when 4

` some code`

else

` some code`

end

A

Equivalent of switch statement.

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

defined?

A

Checks whether an expression is defined.

Returns false if expression isn’t defined.

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

retry

A

If retry appears in rescue clause of begin expression, restart from the beginning of the begin body.

If retry appears in the iterator, the block, or the body of the for expression, restarts the invocation of the iterator call.

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

redo

A

Restarts the iteration of the most internal loop.

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

then

A

Optional keyword for if statements.

i.e

if john == jack then

puts "John and Jack are twins"

end

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

undef

A

Cancels the method definition. Undef can not appear in the method body. By using undef and alias, the interface of the class can be modified independently from the superclass, but notice it may be broke programs by the internal method call to self.

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

unless

unless $baby feed\_meat else feed\_milk end
A

unless expressions are used for reverse conditional execution. It is equivalent to:

if !(cond) ... else ... end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

until

Examples:

until sunrise sleep end

Syntax:

until expr [do] ... end
A

Executes body until condition expression returns true.

i.e. work until tired
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

yield

Examples:

yield data

Syntax:

yield `(' [expr [`,' expr...]]) yield [expr [`,' expr...]]
A

Evaluates the block given to the current method with arguments, if no argument is given, nil is used as an argument. The argument assignment to the block parameter is done just like multiple assignment. If the block is not supplied for the current method, the exception is raised.

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

\a

A

A backslash escape

The BEL character. Rings the console bell.

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

\b

A

A backslash escape for the Backspace character.

17
Q

\f

A

A backslash escape for the Form Feed character. Using a page break sends a Form Feed character

A Form Feed character forces the printer to eject the current page and to continue printing at the top of another. Often, it will also cause a carriage return.

18
Q

\n

A

The escape sequence for the Newline character.

19
Q

\v

A

The escape sequence for the vertical tab character.

20
Q

\r

A

The escape sequence for the Carriage Return character.

21
Q

::

(two colons)

A

The :: is a unary operator that allows: constants, instance methods and class methods defined within a class or module, to be accessed from anywhere outside the class or module.

22
Q

===

(three equals)

A

Used to test equality within a when clause of a case statement.

i.e. (1…10) === 5 returns true.

23
Q

**

A

Exponentiation

24
Q

<<

>>

A

Binary left and right shift operators

i.e. a= 0011

a << 2

25
Q

^

A

Binary XOR Operator copies the bit if it is set in one operand but not both.

a = 1100

b = 1010

(a^b) = 0110

26
Q

~

A

Binary Ones Complement Operator is unary and has the efect of ‘flipping’ bits.

a = 0101 0011

~a = 1010 1100

27
Q

&

A

Binary AND Operator copies a bit to the result if it exists in both operands.

a = 0101

b = 0100

a&b = 0100

28
Q

|

(pipe)

A

Binary OR Operator copies a bit if it exists in either operand.

a = 0101

b= 0110

a|b = 0111

29
Q

<=>

A

Combined comparison operator. Returns 0 if first operand equals second, 1 if first operand is greater than the second and -1 if first operand is less than the second.