Skip to content

Commit

Permalink
Block initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
r-glebov committed Mar 6, 2015
1 parent 4a86300 commit 7953af0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions canvas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Canvas
attr_accessor :width, :height, :color

def initialize
@width = 100
@height = 100
@color = :black
yield(self) if block_given?
end

def draw_rect(x, y, width, height)
# draws a rectangle
end

def to_s
"#{@width}x#{@height} #{@color} canvas"
end
end

canvas = Canvas.new do |c|
c.width = 800
c.height = 600
c.color = :green
end

puts canvas

0 comments on commit 7953af0

Please sign in to comment.