From: Robert Klemme Date: 2012-04-06T07:00:56+09:00 Subject: Re: Call for comments - Structure On Thu, Apr 5, 2012 at 5:18 PM, Hal Fulton wrote: > 2012/4/5 Robert Klemme >> >> On Thu, Apr 5, 2012 at 4:33 PM, Bartosz Dziewoński >> wrote:> Struct just does not have instance variables, which is surprising, >> >> I know - that's the whole point why "#instance_variables returns an >> empty list".  But the question was, whether this is the reason Hal >> calls them "unreal" - and whether it matters.  Both can probably only >> be answered by him since he coined the phrase... >> >> > 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". >> >> Well, obviously it is not a shorthand for the code you show. :-) >> Still it doesn't explain why Hal calls them "unreal".  We are still >> only guessing as to what intentions his might have been. > > Bartosz has understood my point. I don't mind that instance_variables > returns an empty list, but I have been annoyed at the difficulty or > impossibility > of reopening the class to add useful methods that manipulate the > instance data. That I don't understand, maybe that's the reason for the previous discussion: for me it is fairly easy and straightforward Counter = Struct.new :value do def incr(x = 1) self.value += x end alias to_i value end I find that neither difficult nor impossible. What did you have in mind? > It would not be the first time I tried to solve a problem that many or most > others did not perceive at all. :-) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/