Hi there,

In this case you've created @aObjects as a class instance variable, which
means it's not visible to instance methods. Add a constructor to set it up
instead:

class CLWindow

 def initialize
   @aObjects = Array.new
 end

 def add_object
    puts @aObjects.length
 end

end

cl = CLWindow.new
cl.add_object
=> 0

Also watch out in your getObject method, it looks like you're using aObjects
- which will now be a local method variable - instead of @aObjects.

-Charley

On 5/14/07, reinier <[EMAIL PROTECTED]> wrote:

Hi all,

I receive an error stating that the method 'length' is not recognized. I
am using it at an array that exists within a class.
The error occurs at the line stating: nLength = @aObjects.length within
the method of addObject(object)

I think that it doesn't see @aObjects as an array, but I can't figure out
why.
Any help?

Code:
class CLWindow
        @strWindowName
        @aObjects = Array.new

        def setWindowName(windowname)
                @strWindowName = windowname
        end
        def getWindowName()
                return @strWindowName
        end
        def addObject(object)
                nLength = @aObjects.length
                @aObjects.insert(nLength, object)
        end
        def getObject(strName, strType, strFysDes)
                i = 0;
                if (strName!='') then
                        while
(aObjects[i].getObjectName()!=strName)and(i<=aObjects.length)
                                i=i+1
                        end
                else
                        if (strType!='') then
                                while
(aObjects[i].getObjectType()!=strType)and(i<=aObjects.length)
                                        i=i+1
                                end
                        else
                                if (strFysDes!='') then
                                        while
(aObjects[i].getFysicalDescription()!=strFysDes)and(i<=aObjects.length)
                                                i=i+1
                                        end
                                else
                                        return -1
                                end
                        end
                end
                if (i>aObjects.length) then
                        return -1
                else
                        return aObjects[i]
                end
        end
end
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to