Review Ruby Flashcards

1
Q

puts “put s”

A
  • ‘prints’ the following on the screen
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

#

A
  • hash, pound, octothorpe

- starts a comment line or used to disable a line of code

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

“…”

‘…’

A
  • a string of text
  • single quotes do things different. Can be used around a variable in a string, printing the output with single quotes showing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
\+
-
/
*
%
<
><=
>=

PEDMAS
PE(M&D) (A&S)

A

-plus
- minus
- slash (divide)
- asterisk (multiply)
- percent
(modulus - x divided by y with j remaining) The result of % is the j part , the remainder

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

{…}

A
  • this is the format for inserting Ruby computations inside text strings. The result of the computation in the ‘printed’ string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Xxx_yyy

A

Underscore - puts an imaginary space between words in variable names

ex: carpool_capacity

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

4 vs 4.0

A

Integer vs floating point number

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

= (…)

A

= equals is used to give data (numbers, strings, etc. ) names

-sets a variable

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

==

A
  • double equal tests whether two things have the same value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

x=100 vs x = 100?

A
  • it is bad form to leave out the spaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

variable

A
  • any line of code where you set a name = (equal) to a value

ex. type_of_fish = 10

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

print vs puts

A

puts has a linefeed in it

Print does not

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

{} or %{} ?

A

Always use #{} to format strings

%{} is used when you want to apply strings multiple times

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

\n

%q{
-
-
-
}
A
  • escape sequence … linefeed

Print a multi line string

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

“””

A
  • triple quotes works like a string, but you put as many lines of text as you want until you type

“”” again

note: use ‘’’ when you need a multiline string that contains #{} formatting, but you don’t want them to be processed yet or at all. Use “”” For all other multiline strings.

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

gets.chomp

A

gets retrieves a line of text input from the user AND includes a trailing linefeed

chomp suppresses the linefeed

17
Q

gets.chomp.to_i

A

Get a string from the user

chomp off the \n and convert too an integer

18
Q

ARGV

ARGV.first. vs ARGV first 2nd 3rd etc.

A

Argument variable

  • must pass x command line arguments
    ex. Ruby ex13.rb 1st 2nd 3rd etc.

Note: ARGV gets input from the command line while gets.chomp input comes in via the keyboard while the script is running.

ARGV.first is for only one argument

19
Q

$stdin

A

Standard input is stream data

20
Q

close

read

readline

truncate

write(‘stuff’)

seek(0)

A
  • closes the file
  • reads the contents of the file. You can send the results to a variable.
  • reads just one line of a text file.
  • empties the file. Watch out if you care about the file.
  • writes “stuff“ to the file.

Move the read/write location to the beginning of the file.

21
Q

Modifiers

w

r

a

w+

A
  • write
  • read
  • append
  • will open file in read and write mode
22
Q

echo

cat

That;depends;on;how…

A
  • ?
  • concatenate, an old command that puts files together. Mostly it’s just an easy way to print a file to the screen.

You make several lines of into fewer by using ;

23
Q

functions

def

A
  • I name pieces of cove the way variables name strings in numbers.
  • They take arguments the way scripts take ARGV.
  • Using one and two, they let you make your own mini scripts or tiny commands