public
Created

Quiz Generating Script

  • Download Gist
drillsargeant.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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
java_quizz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.