Shared Flashcard Set

Details

Learn Ruby the Hard Way: Part 1
Flashcards to remember terms from the first half of Learn Ruby the Hard Way (for lesson 22)
32
Computer Science
Undergraduate 1
05/07/2012

Additional Computer Science Flashcards

 


 

Cards

Term
puts
Definition
command to output things in Ruby. puts "Hello world!" would print "Hello world!"
Term
#
Definition
pound sign, used to comment out code on its own line. Also used within a puts command to signal a variable, e.g., puts "This is a #{variable}"
Term
+
Definition
plus, used in math
Term
-
Definition
minus, used in math
Term
/
Definition
slash, used in math
Term
*
Definition
asterisk, used in math to multiply
Term
%
Definition
percent, used in math to take the following number percentage of an original number. For example, 100 % 2 takes 2% of 100.
Term
<
Definition
less than
Term
>
Definition
greater than
Term
<=
Definition
less than equal
Term
>=
Definition
greater than equal
Term
string
Definition
a string of letters or words; anything between double quotes. EG, "This is a string". Strings are what the program gives to humans.
Term
%s
Definition
Used to insert a variable in a string. Format is like puts "this is a string with a %s" % variable.

For multiple variables, it looks like, "This is a string with a %s and a %s" % [first_variable, second_variable].
Term
%d
Definition
A second way of inserting variables into strings.
Term
<
Definition
Allows you to create a multi line string. Format is puts >>PARAGRAPH
string
string
string
PARAGRAPH
Term
\n
Definition
Creates a new line in a string.
Term
\t
Definition
creates a tab in a string
Term
\\
Definition
Creates a single backslash (one backslash signals an escape command, the second signals you want just one backslash).
Term
print
Definition
Similar to puts, but doesn't create a new line.
Term
gets.chomp()
Definition
gets accepts a single line of data input by the user, chomp is a string method.
Term
require
Definition
Opens a library in ruby to use?
Term
ARGV
Definition
Argument variable = takes input when running the program and assigns it to a variable. Is constant, so doesn't change.

EG, if you run ruby ex1.rb test1 test2 test3 then test1 would be assigned to the first ARGV variable, test2 the second, etc.
Term
STDIN
Definition
Explicitly tells the .gets command to read from a user's input, instead of trying to read the input as a file. (see exercise 14)
Term
.read()
Definition
reads the text file content; when puts txt.read() will print the content of a text file.
Term
txt.close()
Definition
Term
.close()
Definition
Closes a text file
Term
.readline
Definition
Reads just one line of a text file.
Term
truncate
Definition
Empties the file, watch out if you care about the file.
Term
write(stuff)
Definition
Writes stuff to the file.
Term
def
Definition
starts defining a function
Term
#{}
Definition
used to offset variables within ruby code. Example: puts "Here is a #{variable}" % variable
Term
end
Definition
end a function
Supporting users have an ad free experience!