On Tue, Nov 5, 2013 at 8:47 PM, Stu P. D'naim <lists / ruby-forum.com> wrote:
> yes, this is great, it didn't occur to me that you can pass instance
> object as an argument ... I think now I will be able to use my variables
> that I declare in one class throughout my program (and within all other
> classes). Thank you for your time looking at my feeble code !

I'd have a slightly different organization of the code. For example, a
general rule is to not do work in constructors but rather
initialization.

Then, there is really no need to tie Myfiles's functionality to the
class instance.  People may want to have several of them - that is
more flexible.

-------------------------------------
#menu.rb

require_relative "myfiles.rb"
require_relative "mynumbers.rb"

class Menu
  attr_reader :nums

  def initialize
    @nums = Mynumbers.new
    @nums.calculate
  end
end

# main program

menu = Menu.new
files = Myfiles.new menu
files.show

-------------------------------------
#mynumbers.rb

class Mynumbers
  attr_reader :my_var1, :my_var2

  def calculate
    @my_var1 = rand(2..31)
    @my_var2 = rand(200..310)
  end
end
------------------------------------
#myfiles.rb

class Myfiles
  def initialize menue
    @menue = menue
  end

  def show
    nums = @menue.nums
    puts nums.class
    puts nums.my_var1
    puts nums.my_var2.inspect
  end
end
-------------------------------------

Note, I have no idea what Myfiles really does. It may make sense for a
more realistic example to make Myfiles a member of Menu.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/