back to

Intro to Ruby on Rails

ARCHIVED

Archived: This project has been archived. Cards can no longer be completed.

Rails Controller and Views, Part 2

Stefy
Stefy completed this card.
Last updated

  1. class CraterFill
  2.  class Terrain
  3.  def initialize(h)
  4.       h.each { |key, value| send("#{key}=", value) }
  5.  end
  6.     attr_accessor :water, :earth
  7.  end
  8.  
  9.  def display
  10.  @data.each { |x|
  11.       x.earth.times {putc('X')}
  12.       x.water.times {putc('~')}
  13.  puts
  14.  }
  15.  end
  16.  
  17.  def initialize()
  18.  @data = []
  19.  [3,5,2,6,4,3,6,7,8,1,6,2,7,4,3,2,1].each {|x| @data << Terrain.new({earth: x, water: 0}) }
  20.  end