Beginner question on classes on different files
- From: Edgard Riba <elriba@xxxxxxxxxx>
- Date: Wed, 1 Feb 2006 01:15:27 +0900
Hi,
I'm beginning to work with ruby and I have a conceptual problem. Let's
say I have two files:
hello2.rb:
class Hello2
attr_reader :msg
def initialize
@msg = "Hello, World2"
end
end
and hello.rb
require 'hello2.rb'
class Hello
attr_reader :msg
def initialize
@msg = "Hello, World"
end
end
h = Hello.new()
h2 = Hello2.new()
puts h2.msg
puts h.msg
print "Press RETURN"
$stdin.gets
This is obviously a conceptual excercise. I want to use class
"Hello2" in my hello.rb code. However this doesn't compile.
What is wrong with this code? How is something like this done in Ruby?
Thansk, Edgard
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Beginner question on classes on different files
- From: Stefan Mahlitz
- Re: Beginner question on classes on different files
- From: Tanner Burson
- Re: Beginner question on classes on different files
- Prev by Date: Extend an object with module stored
- Next by Date: Re: Beginner question on classes on different files
- Previous by thread: Extend an object with module stored
- Next by thread: Re: Beginner question on classes on different files
- Index(es):
Relevant Pages
|