class Category
Category
Objects are created upon initializing the app using bin/cli_trivia. This allows the user to choose between random and category. Each Category
has MANY questions, but there is only one of every Category
.
Attributes
id[RW]
name[RW]
questions[RW]
Public Class Methods
all()
click to toggle source
# File lib/cli_trivia/category.rb, line 17 def self.all @@all end
all_by_name()
click to toggle source
A modification of the self.all method to return all Categories alphabetically. Used when categories are printed for user choice.
# File lib/cli_trivia/category.rb, line 23 def self.all_by_name sorted = @@all.sort! {|a, b| a.name <=> b.name} sorted_names = [] sorted.each do |category| sorted_names << category.name end sorted_names end
clear_all()
click to toggle source
# File lib/cli_trivia/category.rb, line 38 def self.clear_all @@all.clear end
new(name, id)
click to toggle source
# File lib/cli_trivia/category.rb, line 10 def initialize(name, id) @id = id @name = name @questions = [] @@all << self end
Public Instance Methods
add_question(question)
click to toggle source