Ruby Flashcards

(52 cards)

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

22
Q

Truncate the file to a specific number of bytes

23
Q

Create a function

24
Q

Define as many arguments as needed

25
Find the starting position of a file
f.seek(0, IO::SEEK_SET)
26
Read a line from a file
f.readline()
27
Equality operator for does not equal
!=
28
Combined comparison operator
Returns 1 if first argument is bigger, 0 if they're the same and -1 if second argument is bigger.
29
Equality operator for equals
==
30
create a range from 1 - 5
(0..5)
31
Run a for loop over an fruit array
for fruit in fruits puts fruit end [This is called a code block]
32
Have a method return the argument untouched
yield
33
Make a variable readable or writable from outside a class
attr_accessor :variable
34
Make a variable readable from outside a class
attr_reader :variable
35
Make variable writable from outside a class
attr_writer :variable
36
Add a global variable to class
$var
37
Add an instance variable to class
@var
38
Add a class variable
@@var
39
Make class functions accessible from anywhere
public
40
Hide class functions from being accessed
private
41
Scope resolution operator
::
42
Allow a class to use methods from a module
extend
43
Give a method or variable another name
alias :newname :oldname
44
Execute a block of code and return value of last evaluated expression
begin
45
Command to run a block while the program is starting up
BEGIN{}
46
Command to run a block after the program has executed
END{}
47
Test if an expression refers to anything recognizable (literal object, local variable that has been initialized, method name visible from the current scope, etc.).
defined?
48
In a begin/end block, it's the command to run a last piece of code before the end
ensure
49
Bumps an iterator (while/until/etc) without executing whatever may remain of the block
next
50
unconditional re-execution of a code block, with the same parameter bindings as the current execution.
redo
51
an exception-handling clause
rescue
52
Inside a rescue clause, this command causes Ruby to return to the top of the enclosing code and try executing the code again
retry