newbie with inheritance issues...

J

Jonathan D. Proulx

Hi,

just to try and wrap my head around ruby I'm attempting to build a
Net::Finger (as a subclass of TCPSocket) class based on the network
I/O example in "Programming Ruby", but my class behave exacly like
it's superclass, where I have 3 (optional?) parameters to initialize
it demands the 2 parameters of the superclass. Any help would be
mutch appriciated.

What am I not seeing/understanding? Here's the code

require 'socket'
module Net
class Finger < TCPSocket
def initialize(who=nil,where="localhost",max_retry=3)
super(where,"finger")
@who, @where, @max_retry = who, where, max_retry
@try = 0
if ! who
@who, @where = gets("who@where? ").split(/@/)
end
end
<more stuff...>
end
end

and here is the behavior from within irb:

irb(main):002:0> fingerme=Net::Finger.new("jon", "csail.mit.edu")
SocketError: getaddrinfo: Servname not supported for ai_socktype
from (irb):2:in `new'
from (irb):2


irb(main):003:0> fingerme=Net::Finger.new("csail.mit.edu","finger")
#<Net::Finger:0x4028b31c>

irb(main):004:0> fingerme.send("jon\n",0)
4

irb(main):005:0> puts fingerme.readlines()
JON Jonathan D. Proulx - Research staff

Thanks,
-Jon
 
T

ts

J> What am I not seeing/understanding?

You are working with 1.6.8, no ?

With 1.6.8, Net::TCPSocket define its own method ::new and don't call
#initialize

J> irb(main):002:0> fingerme=Net::Finger.new("jon", "csail.mit.edu")

This is Net::TCPSocket::new which is called

It work like you want with 1.8.0


Guy Decoux
 
J

Jonathan D. Proulx

On Wed, Aug 27, 2003 at 01:14:11AM +0900, ts wrote:

: You are working with 1.6.8, no ?

Yes.

: With 1.6.8, Net::TCPSocket define its own method ::new and don't call
: #initialize

Odd

: It work like you want with 1.8.0

Thanks.

-Jon
 

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

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top