From: Robert Klemme Date: 2012-04-10T23:02:15+09:00 Subject: Re: New to Ruby, tutorial gives wrong example. On Tue, Apr 10, 2012 at 8:55 AM, Bartosz Dziewoński wrote: > You can use Struct for simple classes like this. The following should > work in the same way as your code: > >  Rectangle = Struct.new :y, :x, :height, :width, :linecolor, > :fillcolor, :linewidth # note the colons > >  rect = Rectangle.new 10, 20, 50, 60, "blue","yellow", 99 # you need > to pass all arguments, linewidth too - it's not optional >  rect.linewidth = 4 That's not true: all values are optional. irb(main):001:0> Rectangle = Struct.new :y, :x, :height, :width, :linecolor, :fillcolor, :linewidth => Rectangle irb(main):002:0> r = Rectangle.new => # irb(main):003:0> r = Rectangle.new 10, 20, 50, 60, "blue","yellow", 99 => # irb(main):004:0> r = Rectangle.new 10, 20, 50, 60, "blue","yellow" => # irb(main):005:0> r.linewidth = 4 => 4 irb(main):006:0> r => # One can also easily define methods with Struct: irb(main):001:0> Rectangle = Struct.new :y, :x, :height, :width, :linecolor, :fillcolor, :linewidth do irb(main):002:1* def paint irb(main):003:2> puts "[]" irb(main):004:2> end irb(main):005:1> end => Rectangle irb(main):006:0> r = Rectangle.new 10, 20, 50, 60, "blue","yellow" => # irb(main):007:0> r.paint [] => nil Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/