Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4109
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Question regarding interaction between modules and classes |
| Date | 2011-05-07 22:34 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <db6fc5702c988fbc83bf9bac48019399@ruby-forum.com> (permalink) |
| References | <fb5b1151925c37ab1b0160d82a746ea4@ruby-forum.com> |
Geometric Patterns wrote in post #997317:
> Hi,
Don't EVER use global variables($).
module Foo
def setup
id = self.object_id
puts id
self.class.class_eval do
@foo= id
def self.foo
@foo
end
end
end
def foo
return self.class.foo
end
end
class Bar
include Foo
end
bar_one = Bar.new
bar_one.setup
p bar_one.foo # => 2148224640
bar_two = Bar.new
p bar_two.foo # => warning: instance variable @foo not initialized
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar | Unroll thread
Question regarding interaction between modules and classes Geometric Patterns <geometric.patterns@gmail.com> - 2011-05-07 22:02 -0500 Re: Question regarding interaction between modules and classes Josh Cheek <josh.cheek@gmail.com> - 2011-05-07 22:31 -0500 Re: Question regarding interaction between modules and classes 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-07 22:34 -0500
csiph-web