Classes and class instance variables in Ruby

I have started learning Ruby..

Since one my colleagues had asked me if I know some great stuffs with Ruby on Rails.

So I have started learning curved in Ruby, and So I have discovered.. Very great features with Ruby.
It has really a very dynamic features. More specifically you have nothing to worry in the memory management.
It has a self contained garbage collection..moreover no declarations required.
And much more, it is really a kind of OOP of those variables.
Really all were treated as Object.

So that is why I have something to share on this simple code snippets I have created.

#sample Class Thing

class Thing

@@num_thingCounter = 0           #class variable same as of static variable
attr_reader :name             #attr_reader - it automatically creates an instance/class variable in a class
attr_reader :description
attr_writer :name             #attr_writer - it added the features for having an accessor methods automatically
attr_writer :description
attr_accessor(:name, :description)      #same with attr_writer only that it can handle many vars

def initialize (name, description)
@@num_thingCounter += 1 = name
self.description = description
@name = name
@description = description

def numthingCounter


#Instance of an object
thing ='LLC Herbals', 'skin products')
puts thing.description = 'LLC Supplements'

puts thing.numthingCounter

thing ='LLC Herbals1', 'skin products')
puts thing.description = 'LLC Supplements1'

puts thing.numthingCounter

#so that is you have noticed it was really very dynamic isn’t it?..
This is something I really want..very programmer friendly.. ^^

Leave a Reply

Your email address will not be published. Required fields are marked *

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