(unknown)

I’m having two problems extending the array class.

First, I am getting instances where super == nil. It seems to me that
this should be impossible. The code that results in super == nil is as
follows:

def TypedArray.initWithArray(parent, content)

	ta = TypedArray.new(parent)
	content.each() { |val| ta << val }
	return ta
end

When I take this returned object and run methods that access super,
super will equal nil. For example:

def [](colNum)

	puts ("******************super == nil") if super == nil;
	return super[@parent.colsIdx[colNum]]
end

The above method will print the “super == nil” string and throw the
exception saying [] is not defined for nil.

Second, I am redefining the [] and []= methods, so within those, I have
to access super[]= and super[] (or else I’ll have an infinite regress).
For example:

def []=(colNum, val)
	super[@parent.colsIdx[colNum]] = val
end

I am getting very odd results. For example, a[0] = “yet another test
col 0” actually sets a[0] to “yet anothyet another test col 0r test col
0”. Moreover, if I insert the following line:

puts(super.type)

I get “String” every time.

These results strike me as anomalous and are too bizarre for me to
explain, especially give the fact that my source code is rather
rudimentary.

I am using ruby 1.6.7 on MacOS X 10.2.3. I am using the version that
came with the developer tools, and ruby --version gives me the
following:

ruby 1.6.7 (2002-03-01) [powerpc-darwin6.0]

Thanks,

Dave

PGP.sig (186 Bytes)

I just compiled and installed Ruby 1.6.8 from source, and I get the
same problems.

PGP.sig (186 Bytes)

···

On Tuesday, December 31, 2002, at 12:51 PM, David Landrith wrote:

I’m having two problems extending the array class.

First, I am getting instances where super == nil. It seems to me that
this should be impossible. The code that results in super == nil is
as follows:

def TypedArray.initWithArray(parent, content)

  ta = TypedArray.new(parent)
  content.each() { |val| ta << val }
  return ta

end

When I take this returned object and run methods that access super,
super will equal nil. For example:

def

  puts ("******************super == nil") if super == nil;
  return super[@parent.colsIdx[colNum]]

end

The above method will print the “super == nil” string and throw the
exception saying is not defined for nil.

Second, I am redefining the and = methods, so within those, I
have to access super= and super (or else I’ll have an infinite
regress). For example:

def =(colNum, val)
super[@parent.colsIdx[colNum]] = val
end

I am getting very odd results. For example, a[0] = “yet another test
col 0” actually sets a[0] to “yet anothyet another test col 0r test
col 0”. Moreover, if I insert the following line:

puts(super.type)

I get “String” every time.

These results strike me as anomalous and are too bizarre for me to
explain, especially give the fact that my source code is rather
rudimentary.

I am using ruby 1.6.7 on MacOS X 10.2.3. I am using the version that
came with the developer tools, and ruby --version gives me the
following:

ruby 1.6.7 (2002-03-01) [powerpc-darwin6.0]

Thanks,

Dave
<PGP.sig>


David King Landrith
(w) 617.227.4469x213
(h) 617.696.7133

One useless man is a disgrace, two
are called a law firm, and three or more
become a congress – John Adams

public key available upon request

Super isn’t a pointer to the parent class’s implementation: it’s a call
to the method you’re in, but in the partent class.

class A
def fred(name)
puts “hello #{name}”
end
end

class B < A
def fred(name)
super(“walter”)
super # calls it with current params
end
end

b = B.new
b.fred(“dave”)

 =>  hello walter
     hello dave

Cheers

Dave

···

On Tue, 2002-12-31 at 11:51, David Landrith wrote:

I’m having two problems extending the array class.

First, I am getting instances where super == nil.

Thanks! That fixed my problem.

Incidentally, how do you get a reference to the superclass?

PGP.sig (186 Bytes)

···

On Tuesday, December 31, 2002, at 01:50 PM, Dave Thomas wrote:

On Tue, 2002-12-31 at 11:51, David Landrith wrote:

I’m having two problems extending the array class.

First, I am getting instances where super == nil.

Super isn’t a pointer to the parent class’s implementation: it’s a call
to the method you’re in, but in the partent class.

class A
def fred(name)
puts “hello #{name}”
end
end

class B < A
def fred(name)
super(“walter”)
super # calls it with current params
end
end

b = B.new
b.fred(“dave”)

 =>  hello walter
     hello dave

Cheers

Dave


David King Landrith
(w) 617.227.4469x213
(h) 617.696.7133

One useless man is a disgrace, two
are called a law firm, and three or more
become a congress – John Adams

public key available upon request


David King Landrith
(w) 617.227.4469x213
(h) 617.696.7133

One useless man is a disgrace, two
are called a law firm, and three or more
become a congress – John Adams

public key available upon request