Last active
December 25, 2015 22:29
-
-
Save Ravenstine/7049701 to your computer and use it in GitHub Desktop.
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
# Main file for | |
require 'csv' | |
class Card | |
attr_writer :answer | |
attr_accessor :question | |
def initialize(question_input, answer_input) | |
@question = question_input | |
@answer = answer_input | |
end | |
def is_answer?(user_input) | |
@answer == user_input | |
end | |
end | |
class Deck | |
def initialize(card_array) | |
@cards = [] | |
end | |
def pick_card | |
return @cards[rand(@cards.length)] | |
end | |
def self.from_csv(file_name) | |
card_list = [] | |
CSV.foreach(file_name) do |row| | |
card_list << Card.new(row[0], row[1]) | |
end | |
return Deck.new(card_list) | |
end | |
end | |
class Controller | |
attr_reader :card_deck | |
def initialize | |
@card_deck = Deck.new | |
end | |
end | |
flash_cards = Controller.new | |
# p flash_cards.show_deck | |
# flash_cards.create_card! | |
# p flash_cards.show_deck | |
#.card_deck.pick_card | |
#flash_cards.card_deck.pick_card.is_answer?("sausage") | |
flash_cards.card_deck.from_csv('cards.csv') | |
p flash_cards.card_deck.pick_card |
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
To create a second name for the variable or method.,alias | |
A command that appends two or more objects together.,and | |
Designates code that must be run unconditionally at the beginning of the program before any other.,BEGIN | |
Delimits a begin block of code, which can allow the use of while and until in modifier position with multi-line statements.,begin | |
Gives an unconditional termination to a code block and is usually placed with an argument.,break | |
starts a case statement; this block of code will output a result and end when it's terms are fulfilled which are defined with when or else.,case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment