Gabriel Dragffy wrote:
> I still struggling
> with trying to identify the differences between self.???, @, and @@.

Gabriel -

I'll take a crack at trying to help you with these symbols.

@ - this designates an instance variable within an object. The value of 
this variable differs between instances of the same class.

@@ - this is a class variable. The value of this variable is the same 
between ALL instances of the same class.

self.* - this is used to declare class methods. You call these methods 
directly on a class rather than using a instance of a class.

Below is a little irb session to demonstrate things a bit more:

irb(main):001:0> class Foo
irb(main):002:1>   def initialize
irb(main):003:2>     @inst = 0
irb(main):004:2>     @@cls = 0
irb(main):005:2>   end
irb(main):006:1>   def increment_instance
irb(main):007:2>     @inst += 1
irb(main):008:2>   end
irb(main):009:1>   def increment_class
irb(main):010:2>     @@cls += 1
irb(main):011:2>   end
irb(main):012:1>   def print_stats
irb(main):013:2>     puts "class var: #{@@cls}, instance var: #{@inst}"
irb(main):014:2>   end
irb(main):015:1>   def self.say_hello
irb(main):016:2>     puts "Hello from a class method!"
irb(main):017:2>   end
irb(main):018:1> end
=> nil
irb(main):019:0>
irb(main):020:0* one_foo = Foo.new
=> #<Foo:0x28d0f34 @inst=0>
irb(main):021:0> two_foo = Foo.new
=> #<Foo:0x28ced60 @inst=0>
irb(main):022:0>
irb(main):023:0* 2.times{ one_foo.increment_instance }
=> 2
irb(main):024:0> one_foo.increment_class
=> 1
irb(main):025:0>
irb(main):026:0* one_foo.print_stats
class var: 1, instance var: 2
=> nil
irb(main):027:0>
irb(main):028:0* two_foo.increment_instance
=> 1
irb(main):029:0> two_foo.increment_class
=> 2
irb(main):030:0>
irb(main):031:0* two_foo.print_stats
class var: 2, instance var: 1
=> nil
irb(main):032:0>
irb(main):033:0* Foo.say_hello
Hello from a class method!
=> nil

Welcome to ruby! (it's wayyyy better than python :)

-- 
Posted via http://www.ruby-forum.com/.