• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/10

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

10 Cards in this Set

  • Front
  • Back
How to print to screen?
"puts "

"p " (also prints object type)
How to output to screen without newline?
print
How to evaluate variable inside double quotes?
use "test #{ variable}"
How to open and close a file?
aFile = File.new("filename", "mode")
# ... process the file
aFile.close
How to read the first 20 characters in a file?
sysread can be used to read the contents of a file

e.g. content = aFile.sysread(20)
how to read the lines of a textfile?
arr = IO.readlines("fileltest.txt")
How to read lines with Ruby?
File.open('test.txt').each_line{ |s|
puts s
}

or

File.foreach('test.txt') { |s|
puts s
}

close file
What is the output?

def callBlock
yield
yield
end


callBlock { puts "In the block" }
In the block
In the block
What does this produce?

a = %w( ant bee cat dog elk ) # create an array
a.each { |animal| puts animal } # iterate over the contents
ant
bee
cat
dog
elk
What is the effect of this?

a = %w{ ant bee cat dog elk }
an array of string with values e.g.

a[0] >> "ant"
a[3] >> "dog"