Created
February 22, 2012 16:14
-
-
Save syntacticsugar/1885822 to your computer and use it in GitHub Desktop.
Quiz Generating Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless ARGV[0] # unless we *do* have the argument :) | |
puts "So, usage is as follows: 'ruby <flashcardscript.rb> <flashcardtext>." | |
exit | |
end | |
officialexam = [] | |
quiz = Struct.new(:question, :answer) # in which we construct quiz/answer mechanism, sure beats having to create a new class | |
# begin fetching quiz data | |
# open text file, extract contents, and populate our 'officialexam' array | |
File.open(ARGV[0], "rb").each do |row| | |
if row =~ /(.*)\s{3,10}(.*)/ # ruby's pattern-matcher! :D :D & psycho regex | |
officialexam << quiz.new($1.strip,$2.strip) # array population time!! | |
end | |
end | |
# officialexam = officialexam.sort_by{rand} | |
officialexam.replace(officialexam.sort_by{rand}) # shuffles my exam questions | |
# begin running 'drillsargeant' function until all questions are exhausted | |
until officialexam.empty? | |
drillsargeant = officialexam.pop # wherein i destructively run through questions | |
print "#{drillsargeant.question}" | |
if STDIN.gets.chomp.downcase == drillsargeant.answer.downcase | |
puts "Yes, #{drillsargeant.answer} is correct. Moving on." | |
else | |
puts "Actually, it's #{drillsargeant.answer}." | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instead of an object variable, what exists: object reference variable | |
Does an object variable exist (y/n): n | |
An object reference variable holds ____ that represent a way to ____ a ____: bits access object | |
List in order, what happens here: Dog myDog = new Dog; 1. declaration of an object reference variable 2. object creation 3. assignment | |
An array is a ____: object | |
An array holds either a p_____ or a o_____ _____: primitive object reference | |
Every element inside an array: is a ______ variable | |
Dog[] dogvalues = new Dog[5]; What's actually missing here? ___ ___. And how would we populate the first line? Dog objects dogvalues[0] = new Dog; | |
A class describes what a ____ ____ and what a ____ ____: object knows object does | |
Arguments vs Parameters. A ____ uses ____, while a _____ passes _____. method parameters caller arguments | |
Things an object knows are its: ____ ____ instance variables | |
Things an object does are its _____ methods | |
Methods can use ____ ____ so that objects of the same _____ can behave differently. instance variables type | |
Values passed in and out of methods can be implicitly promoted to a ___ ___ or explicitly cast to a ___ ___ larger type smaller type | |
The value you pass as an argument to a method can be a ___ value (2, 'c', etc') or a variable of the declared parameter ___ (ex, 'x' where 'x' is an int variable). (There are other things you can pass as arguments, but we're not there yet.) literal type | |
If a method declares a non-void return type, it MUST return a value compatible with the declared return ___: type | |
Instance variables are declared inside a ___ but not inside a ____. Local variables are declared within a ____. class method method | |
Local variables must be _____ before use! initialized. | |
Local variables do NOT, by default, have a _____: value | |
Two strings that have the same characters (ie, "volcanoooo") are meaningfully _____: equal | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment