Ruby Flashcards

1
Q

Output a string on its own line

A

puts

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

Comment out a line

A

#

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

Operator to find the remainder when two numbers are divided

A

%

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

Format sequence to convert argument to string

A

%s

Example: puts “Let’s talk about %s.” % name

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

Format sequence to convert argument as a decimal

A

%d

example: puts “He’s %d pounds heavy.” % my_weight

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

Output string on the same line

A

Print

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

Escape sequence to create a new line

A

/n

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

write a paragraph of text

A

«s something going on here.
With the PARAGRAPH thing
PARAGRAPH

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

Print variable to the next line after “puts”

A

,

Example:
puts “Here are the days: “, days

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

Escape sequence to create a tab

A

\t

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

Escape sequence to make a backslash

A

\

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

Take user feedback

A

gets

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

Return a String, removing carriage return characters

A

.chomp()

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

Load a library

A

require

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

String interpolation

A

{}

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

Standard input

A

STDIN

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

Pass an open file as an argument

A

File.open(filename)

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

The name of your script

A

$0

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

Put argument inputs from command line into an array

A

ARGV

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

Add information to a file

A

.write(“String”)

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

Read all the data in a file

A

.read()

22
Q

Truncate the file to a specific number of bytes

A

.truncate()

23
Q

Create a function

A

def

24
Q

Define as many arguments as needed

A

*args

25
Q

Find the starting position of a file

A

f.seek(0, IO::SEEK_SET)

26
Q

Read a line from a file

A

f.readline()

27
Q

Equality operator for does not equal

A

!=

28
Q

Combined comparison operator

A

Returns 1 if first argument is bigger, 0 if they’re the same and -1 if second argument is bigger.

29
Q

Equality operator for equals

A

==

30
Q

create a range from 1 - 5

A

(0..5)

31
Q

Run a for loop over an fruit array

A

for fruit in fruits
puts fruit
end
[This is called a code block]

32
Q

Have a method return the argument untouched

A

yield

33
Q

Make a variable readable or writable from outside a class

A

attr_accessor :variable

34
Q

Make a variable readable from outside a class

A

attr_reader :variable

35
Q

Make variable writable from outside a class

A

attr_writer :variable

36
Q

Add a global variable to class

A

$var

37
Q

Add an instance variable to class

A

@var

38
Q

Add a class variable

A

@@var

39
Q

Make class functions accessible from anywhere

A

public

40
Q

Hide class functions from being accessed

A

private

41
Q

Scope resolution operator

A

::

42
Q

Allow a class to use methods from a module

A

extend

43
Q

Give a method or variable another name

A

alias :newname :oldname

44
Q

Execute a block of code and return value of last evaluated expression

A

begin

45
Q

Command to run a block while the program is starting up

A

BEGIN{}

46
Q

Command to run a block after the program has executed

A

END{}

47
Q

Test if an expression refers to anything recognizable (literal object, local variable that has been initialized, method name visible from the current scope, etc.).

A

defined?

48
Q

In a begin/end block, it’s the command to run a last piece of code before the end

A

ensure

49
Q

Bumps an iterator (while/until/etc) without executing whatever may remain of the block

A

next

50
Q

unconditional re-execution of a code block, with the same parameter bindings as the current execution.

A

redo

51
Q

an exception-handling clause

A

rescue

52
Q

Inside a rescue clause, this command causes Ruby to return to the top of the enclosing code and try executing the code again

A

retry