overriding NArray.new

H

Hans Fugal

class Sound < NArray
def initialize
puts 'Chunky. Bacon.'
end
end

Sound.new(4,10) #=> Sound.sfloat(10): [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0 ]


I'm not sure why this is, but I bet it has something to do with the way
NArray is implemented in C. That's keen, but I'd really like to
override new (I'd do something more useful than above, I promise).
Overriding other methods of NArray is no problem. Is there any hope?
 
K

Kevin Brown

class Sound < NArray
def initialize
puts 'Chunky. Bacon.'
end
end

Sound.new(4,10) #=> Sound.sfloat(10): [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0 ]


I'm not sure why this is, but I bet it has something to do with the way
NArray is implemented in C. That's keen, but I'd really like to
override new (I'd do something more useful than above, I promise).
Overriding other methods of NArray is no problem. Is there any hope?

Never used NArray before, but try calling super() with the args you'd normally
give an NArray if it wasn't a Sound so that NArray's initialize method gets
called. :)
 
H

Hans Fugal

Never used NArray before, but try calling super() with the args you'd
normally give an NArray if it wasn't a Sound so that NArray's
initialize method gets called. :)

Yup, I do want to call super. My example was contrived such as to make
it painfully obvious that even if you don't call super, NArray's
initialize gets magically called instead of the subclass's.
 
H

Hans Fugal

Ah, I figured it out:

class Sound < NArray
def self.new(typecode, frames, channels)
super
end
end

That's an oversimplified version of the end product.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Homework Help - Methods 5
extending NArray 2
Help translating from GLUT to FXRuby?? 0
generate texture 1
Overriding delegated methods 5
n00b question 4
[ANN] Decimal 0.0 released 7
OpenGL 3D gears demo for Ruby 1

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top