What is a class instance variable in Ruby?

The Variables starts with the @ character are called instance variables. They belong to individuals’ objects – or instances of the class. It is not necessary to pre-declare these variables. See an example:

class  City

            def set_name (aName)

                        @cityname = aName

            end

end

Here variable ‘cityname, begin with the @ character is called instance variable.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.