# (unknown)

**URL:** <https://rubytalk.org/t/unknown/3874>\
**Category:** ruby-talk\
**Created:** [31 December 2002 17:51 UTC](https://rubytalk.org/t/unknown/3874 "2002-12-31T17:51:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_King\_Landrith2](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@David\_King\_Landrith2](https://rubytalk.org/u/David_King_Landrith2)\
**Post date:** [31 December 2002 17:51 UTC](https://rubytalk.org/t/unknown/3874/1 "2002-12-31T17:51:31Z")

</div>

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](https://rubytalk.org/uploads/short-url/zUQPrVPtCdAKaep6ArwpEsqSqiI.sig) (186 Bytes)

---

<div class="post-metadata">

**Author:** ![David\_King\_Landrith2](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@David\_King\_Landrith2](https://rubytalk.org/u/David_King_Landrith2)\
**Post date:** [31 December 2002 18:00 UTC](https://rubytalk.org/t/unknown/3874/2 "2002-12-31T18:00:12Z")

</div>

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

[PGP.sig](https://rubytalk.org/uploads/short-url/1UcCFRGqUVzZvC7vlEEEj12gA0C.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

---

<div class="post-metadata">

**Author:** ![Dave\_Mail\_Archive](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Dave\_Mail\_Archive](https://rubytalk.org/u/Dave_Mail_Archive)\
**Post date:** [31 December 2002 18:50 UTC](https://rubytalk.org/t/unknown/3874/3 "2002-12-31T18:50:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_King\_Landrith](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@David\_King\_Landrith](https://rubytalk.org/u/David_King_Landrith)\
**Post date:** [1 January 2003 04:50 UTC](https://rubytalk.org/t/unknown/3874/4 "2003-01-01T04:50:25Z")

</div>

Thanks! That fixed my problem.

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

[PGP.sig](https://rubytalk.org/uploads/short-url/24iAxkTP7tcse2XsLP4T40Eo1uL.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
