Forum: Ruby subclassing question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5c0223a3a3fd877455f26c2cbde9038d?d=identicon&s=25 Jason Wold (jasonwold)
on 2006-01-29 19:13
(Received via mailing list)
I'm trying to subclass Ncurses::WINDOW but it just seems to hijack my
class.  My subclass' initialize never gets called.   I can't add any new
methods.

# cat test
#!/usr/bin/ruby
begin
  require 'rubygems'
rescue LoadError
ensure
  require 'ncurses'
end

class MyClass < Ncurses::WINDOW

  def initialize(arbstring)
    puts lkjlkdsf # this should generate an error
  end

end

Ncurses.initscr

begin
  foo = MyClass.new(10,10,0,0)
ensure
  Ncurses.endwin
end

puts foo.class  # this should return MyClass

# ./test
=> Ncurses::Window



Two things wrong.
-initialize never gets called.  If it did "puts lkjlkdsf" would generate
an
error.

-"puts foo.class" returns Ncurses::WINDOW where I would expect MyClass.

As a side note, Ncurses::WINDOW doesn't even exist until Ncurses.initscr
is
called.  Perhaps it's dynamic nature is getting in the way?

Jason
This topic is locked and can not be replied to.