Learn Ruby the Hard Way: Words & Symbols Flashcards

1
Q

terminal:

irb

A

into ruby realm!

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

mkdir NAME

A

Make Directory

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

cd NAME

A

Change Directory

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

puts

A

write out string and create new line

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

ruby ex1.rb

A

run ex1.rb

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

Caret character, points out where the error is

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

#

A

Anything after this on the same line is a comment

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

+

A

plus which can add two things

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

-

A

minus which can subtract two things

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

/

A

slash which can divide two things

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

*

A

asterisk which can multiply two things

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

%

A

percent which does the modulo thing and string substitution; example

“We are a %s and %s.” % [animal1, animal2]

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

<

A

less than

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

>

A

greater than

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

<=

A

less-than-equal

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

> =

A

greater-than-equal

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

=

A

equal, set a variable

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

_

A

underscore

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

format string

A

“ANYTHINGINHERE”

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

string

A

something a human will read or be given

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

string interpolation

A

put a defined string within a string using “#{}”

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

\n

A

put a new line character into the string at that point.

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

document syntax, which uses «NAME and works like a string, but you also can put as many lines of text you as want until you type NAME again.

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

\

A

These two characters will print just one back-slash.

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

\

A

Escape technique.
To solve this problem you escape double-quotes and single-quotes so Ruby knows to include in the string. Here’s an example:

“I am 6’2" tall.” # escape double-quote inside string
‘I am 6'2” tall.’ # escape single-quote inside string

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

\t

A

tabbed

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

print

A

Notice that we are using print instead of puts to do the prompting. print doesn’t add a new line automatically, so your answer can go on the same line as the question. puts on the other hand, adds a newline automatically.

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

.gets

A

takes user input and puts on new line

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

.chomp

A

since .gets automatically adds a new line this method will destroy that new line, putting the response on the same line

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

require “whatever”

A

his is how you add features to your script from the Ruby feature set or other sources (e.g., Ruby Gems, stuff you wrote yourself). Rather than give you all the features at once, Ruby asks you to say what you plan to use. This keeps your programs small, but it also acts as documentation for other programmers who read your code later.

feature = libraries = modules

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

feature

A

= libraries = modules

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

argument

A

You know how you type ruby ex13.rb to run the ex13.rb file? Well the ex13.rb part of the command is called an “argument”
What we’ll do now is write a script that also accepts arguments.

Type this program and I’ll explain it in detail:

1
2
3
4
5
6
first, second, third = ARGV 

puts “The script is called: #{$0}”
puts “Your first variable is: #{first}”
puts “Your second variable is: #{second}”
puts “Your third variable is: #{third}”
The ARGV is the “argument variable”, a very standard name in programming, that you will find used in many other languages.

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

ARGV

A

The ARGV is the “argument variable”, a very standard name in programming, that you will find used in many other languages. It’s in all caps because it’s a constant, meaning you shouldn’t change the value once it’s been assigned. This variable holds the arguments you pass to your Ruby script when you run it.

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

STDIN

A

Also notice that we’re using STDIN.gets instead of plain ‘ol gets. That is because if there is stuff in ARGV, the default gets method tries to treat the first one as a file and read from that. To read from the user’s input (i.e., stdin) in such a situation, you have to use it STDIN.gets explicitly.

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

prompt

A

puts forward something before the user input, like >

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

Hard coding

A

“Hard coding” means putting some bit of information that should come from the user as a string right in our program. That’s bad because we want it to load other files later. The solution is to use ARGV and STDIN.gets to ask the user what file they want instead of “hard coding” the file’s name.

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

txt = File.open(filename)

puts txt.read()

A

We call a function on txt. What you got back from open is a file, and it’s also got commands you can give it. You give a file a command by using the . (dot or period), the name of the command, and parameters. Just like with File.open. The difference is that when you say txt.read() you are saying, “Hey txt! Do your read command with no parameters!”
Reads the contents of the file, you can assign the result to a variable.

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

.close()

A

close files you open

Closes the file. Like File->Save.. in your editor.

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

.readline()

A

Reads just one line of a text file.

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

.truncate

A

Empties the file, watch out if you care about the file.

41
Q

.write(stuff)

A

write stuff to file

42
Q

File.open(filename, ‘w’)

A

instead of opening regularly which is in read for, open in write form

43
Q

File.exists?

A

True if it exists, False if it doesn’t

44
Q

type WHAT.txt

A

output the text

45
Q

Functions

A

They name pieces of code the way variables name strings and numbers.

They take arguments the way your scripts take ARGV.

Using #1 and #2 they let you make your own “mini scripts” or “tiny commands”.

46
Q

Run, Call, Use a function?

A

“To ‘run’, ‘call’, or ‘use’ a function all mean the same thing.”

47
Q

IO::SEEK_SET

A

IO::SEEK_SET | Seeks to the absolute location given by amount

48
Q

What’s the difference between %s and %d?

A

%s expects a string, while %d expects a number

49
Q

alias

A

associate a method and make it synonymous with another method.

To alias a method or variable name in Ruby is to create a second name for the method or variable. Aliasing can be used either to provide more expressive options to the programmer using the class, or to help override methods and change the behavior of the class or object.

50
Q

and

A

flow control operator with low precedence that means do x and do y. Not to be confused with &&, which is a boolean operator with high precedence.

51
Q

BEGIN

A

Designates, via code block, code to be executed unconditionally before sequential execution of the program begins. Sometimes used to simulate forward references to methods (comes from http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-BEGIN,and I’m only slightly sure of what it means).

52
Q

begin

A

Together with end, delimits what is commonly called a “begin” block (to distinguish it from the Proc type of code block).

53
Q

break

A

terminates execution of a code block and jumps out of it. Think of a case statement, as that’s where I’m most familiar with seeing it being used.

54
Q

case

A

INVESTIGATE

55
Q

class

A

defines an object and its methods that can be used by ruby

56
Q

def

A

used to define a function

57
Q

defined?

A

determines if a method refers to something directly (a string, a number, etc.)

58
Q

do

A

execute everything that follows as if it were part of the same block

59
Q

END

A

defines a section of code that can be run at the end of a code block

60
Q

end

A

end of a block of code

61
Q

ensure

A

usually run with a rescue statement, even if the rescue statement doesn’t get run, the ensure statement will run

62
Q

for

A

keyword to define the start of a loop

63
Q

in

A

run the steps in the for loop that match this condition

64
Q

module

A

synonymous with function, it’s a scope where local variables are not aware of other variables

65
Q

not

A

is not this value

66
Q

redo

A

re-executes a code block without regard to conditions of variables or state of the program

67
Q

rescue

A

error handling section of code

68
Q

retry

A

associated with rescue, has the program try the section of code where the rescue statement resides agan

69
Q

return

A

value sent out from a function to the main routine

70
Q

self

A

the area of code being rn at any given time

71
Q

super

A

INVESTIGATE

72
Q

then

A

makes possible a conditional statement on a single line (i.e. without having to use a semi-colon)

73
Q

undef

A

dereference a method or class for use in a given scope

74
Q

yield

A

called from inside a method body, yields control to the code block (If any) supplied as part of the method call. if no code block has been supplied, calling yield raises an exception.

75
Q

constants

A

data type that starts with a capital letter. if value is changed ruby will warn you that you have changed a constant.
Pi = 3.14

76
Q

string

A

a collection of character

a = “hello there”

77
Q

numbers

A

any digital value

a= 1, b = 24

78
Q

ranges

A

a grouping of numbers (1..10) or (1…10)

79
Q

arrays

A

a special container that can contain many values under the same variable name value

array = [“one”, 2, “three”, 4]

80
Q

hashes

A

similar to an array, but with a way to associate values

hash = {“dog” => “canine”, “cat” => “feline”}

81
Q

\a

A

INVESTIGATE

82
Q

\f

A

INVESTIGATE

83
Q

\n

A

prints a new line

84
Q

\r

A

prints a literal carriage return

85
Q

\t

A

tab

86
Q

\v

A

vertical tab

87
Q

::

A

call a constant value

88
Q

[]

A

element set, used with arrays

89
Q

**

A

exponent arithmetic operator

90
Q

-(unary)

A

INVESTIGATE

91
Q

+(unary)

A

INVESTIGATE

92
Q

!

A

logical not operator

93
Q

~

A

binary ones complement operator

94
Q

«

A

binary left shift operator

95
Q

> >

A

binary right shift operator

96
Q
A

combined comparison operator
a bigger than b, 1
equal, 0
b bigger than a, -1

97
Q

===

A

special equals option when used within a case statement

98
Q

!=

A

not equal

99
Q

%w

A

white space separated array
square brackets %w[…], curly braces %w{…} or even something like exclamation marks %w!…!. All of these have the same behavior (returning an array)