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

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.179 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.178 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.177 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.176 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.175 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.174 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.173 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.172 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.171 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.170 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.169 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.167 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.166 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.165 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.164 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.163 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.162 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.161 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb
trackler-2.2.1.160 tracks/ruby/exercises/kindergarten-garden/.meta/solutions/kindergarten_garden.rb