Skip to content

Instantly share code, notes, and snippets.

@rickychilcott
Created July 13, 2022 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickychilcott/89f136902abf48026df2a34219e3c22a to your computer and use it in GitHub Desktop.
Save rickychilcott/89f136902abf48026df2a34219e3c22a to your computer and use it in GitHub Desktop.
Fun with Goals and Strategies
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