From: "Bartosz Dziewoński" Date: 2012-04-05T23:33:08+09:00 Subject: Re: Call for comments - Structure W dniu 5 kwietnia 2012 14:21 użytkownik Robert Klemme napisał: >> Unlike Struct, it creates a "real" class, and it has real instance >> variables >> with predictable names. > > Why are Struct generated classes not real?  Or does this only refer to > the fact that #instance_variables returns an empty list?  If so why does > it matter? No. Struct just does not have instance variables, which is surprising, if you assume that "Point = Struct :x, :y" is a shorthand for "class Point; attr_accessor :x, :y; def initialize x, y; @x, @y = x, y; end; end". For example this is not valid code: Point = Struct.new :x, :y class Point def distance other Math.sqrt((@x-other.x)**2 + (@y-other.y)**2) end end irb(main):007:0> a = Point.new 1, 2 => # irb(main):008:0> b = Point.new -1, 3 => # irb(main):009:0> a.distance b NoMethodError: undefined method `-' for nil:NilClass from (irb):4:in `distance' from (irb):9 from F:/Ruby193/bin/irb:12:in `
' -- Matma Rex