Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4106

Question regarding interaction between modules and classes

From Geometric Patterns <geometric.patterns@gmail.com>
Newsgroups comp.lang.ruby
Subject Question regarding interaction between modules and classes
Date 2011-05-07 22:02 -0500
Organization Service de news de lacave.net
Message-ID <fb5b1151925c37ab1b0160d82a746ea4@ruby-forum.com> (permalink)

Show all headers | View raw


Hi,

In the code below, is there a way to learn @foo from $bar_one
using $bar_two?

Many thanks in advance!!


----------------

#!/usr/bin/ruby -w

module Foo
   def setup
      @foo = self.object_id
   end
   def foo
      return @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 | NextNext in thread | Find similar | Unroll thread


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