Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Module Mixin & Class Variables

Reply
Thread Tools

Module Mixin & Class Variables

 
 
JP Billaud
Guest
Posts: n/a
 
      03-06-2011
Hey,

I would like to understand better what happens when one includes a
module with class variables inside a class.

===

module MyModule

@@test = "test"

def self.my_test
puts "From Module"
puts @@test.object_id
end
end

class B
include MyModule

def self.my_test
puts "From Class"
puts @@test.object_id
end
end

B.my_test
MyModule.my_test

> From Class
> -607833218
> From Module
> -607833218


===

Doing so, the output shows that in both cases the @@test object is the
same. Does someone have the big picture about class variables look up
while mixin a module inside a class?

Thanks,

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mixin technique overrides variables Konrad K. Ruby 6 01-05-2011 05:20 PM
Mixin module with class variables and class methods John Lane Ruby 6 02-09-2010 09:48 PM
class, Module and Mixin Sijo Kg Ruby 1 09-24-2009 10:50 AM
Mixin a module method as a class method Farrel Lifson Ruby 9 10-19-2006 12:06 PM
calling binding() within a module method (for mixin)????? Ben Ruby 3 11-10-2004 10:24 PM



Advertisments