From: Logan Capaldo Date: 2006-05-16T05:21:36+09:00 Subject: Re: Struct.new vs class On May 15, 2006, at 8:43 AM, Mark Volkmann wrote: > On 5/15/06, Logan Capaldo wrote: >> >> On May 15, 2006, at 2:44 AM, Giles Bowkett wrote: >> >> > OK, so I have this class and it could probably be a Struct. >> > >> > class Sample >> > >> > # I should probably turn this whole class into a simple >> > Struct.new(etc.) statement >> > >> > attr :note_length, true >> > attr :track, true >> > attr :note, true >> > attr :channel, true >> > attr :threshold, true >> > attr :notes, true >> > >> > def initialize(note_length, sequence, note, channel, threshold, >> > notes) >> > @note_length = note_length >> > >> > @track = Track.new(sequence) >> > @track.sequence.tracks << @track # butt >> > >> > @note = note >> > @channel = channel >> > @threshold = threshold >> > @notes = notes >> > end >> > >> > end >> > >> > >> >> class Sample < Struct.new(:note_length, :sequence, :note, :channel, >> etc.) >> def initialize >> super >> # blah >> end >> end > > What is this supposed to do? It doesn't seem to allow me to create a > Sample object and pass parameters to new. I think the OP wanted that. > > -- > R. Mark Volkmann > Object Computing, Inc. > oops sorry. Whenever I answer questions like this, half the time I think the questioner is asking to be reminded of the idiom (because that's what usually happens to me), and I tend to leave stuff out.