Created
July 13, 2022 13:28
-
-
Save rickychilcott/89f136902abf48026df2a34219e3c22a to your computer and use it in GitHub Desktop.
Fun with Goals and Strategies
This file contains hidden or 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
class Base | |
def initialize(id) | |
@id = id | |
end | |
def name | |
"#{self.class.name} #{@id}" | |
end | |
end | |
class Goal < Base | |
end | |
class Strategy < Base | |
end | |
def roman_numeral(num) | |
case num | |
when 1 | |
"I" | |
when 2 | |
"II" | |
when 3 | |
"III" | |
when 4 | |
"IV" | |
end | |
end | |
def alpha_numeral(num) | |
("A".."Z").to_a[num - 1] | |
end | |
goals_and_strategies = [Strategy.new(1), Goal.new(1), Goal.new(2), Strategy.new(2), Goal.new(3), Strategy.new(3), Goal.new(4), Strategy.new(4)] | |
strategy_index = 0 | |
goal_index = 0 | |
goals_and_strategies.each.with_index do |item, index| | |
if item.is_a?(Goal) | |
goal_index += 1 | |
pp [" ", alpha_numeral(goal_index), item.name].join(" ") | |
elsif item.is_a?(Strategy) | |
strategy_index += 1 | |
goal_index = 0 | |
pp [roman_numeral(strategy_index), item.name].join(" ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment