Sha256: 19cfc66130964ea241a9407f6ffdf1dea64311682b9151c58ba49a280a1e13db
Contents?: true
Size: 756 Bytes
Versions: 396
Compression:
Stored size: 756 Bytes
Contents
class Garden attr_reader :pots, :students def initialize(diagram, students = default_children) @pots = parse(diagram) @students = students.sort assign_pots end def default_children %w(Alice Bob Charlie David Eve Fred Ginny Harriet Ileana Joseph Kincaid Larry) end private def parse(diagram) diagram.split("\n").map do |row| row.split('').map do |sign| plants[sign] end end end def plants { 'G' => :grass, 'V' => :violets, 'R' => :radishes, 'C' => :clover } end def assign_pots students.each_with_index do |student, i| instance_eval "def #{student.downcase}; position = #{i}*2; pots[0][position,2] + pots[1][position,2]; end" end end end
Version data entries
396 entries across 396 versions & 1 rubygems