How to call a class from another script?

A

Anthony Ob

Well I got this script:

puts "Do you feel, good, bad, or neutral?"

feelings = gets.chomp

STDOUT.flush

puts "You are feeling " + feelings

and I want to add the name class from this script:

puts "Hello, what is your name?"

name = gets.chomp

STDOUT.flush

puts "Hello, " + name


How would I do that?
 
H

Hassan Schroeder

and I want to add the name class from this script:

puts "Hello, what is your name?"

=A0 =A0 =A0name =3D gets.chomp

If that's the whole "script", 'name' is a variable, not a class.

Again -- find and work through a tutorial on basic Ruby.

--=20
Hassan Schroeder ------------------------ (e-mail address removed)
twitter: @hassan
 
S

susan hall

truth that if he look like he want swat him on the nozzles
yes it lite trouble but there lab=2C can automatic every command dang. th=
ats make too of us. bouble dang=2C save a lot work uh auto speaker u think =
that the directing. awersome we are save. p.s hi susan
Date: Sat=2C 26 Feb 2011 13:39:36 +0900
From: (e-mail address removed)
Subject: Re: How to call a class from another script?
To: (e-mail address removed)
=20
=20
=20
That dog wouldn't bark :)
=20
Maybe you should ask a more specific question=2C or run through a
basic tutorial on Ruby first.
=20
--=20
Hassan Schroeder ------------------------ (e-mail address removed)
twitter: @hassan
=20
=
 
J

J. K.

hello anthony,

first, i completely agree with hassan that a basic ruby tutorial is
absolutely the best place to start. there are many very good ones
available - do a quick google search for "ruby tutorial."

second, if i understand your question - try this:

#############
class NameGetter
attr_reader :name
def initialize
puts "Hello, what's your name?"
@name = gets.chomp
puts "Hello, " + @name
end
end #class

class NameAndFeelingGetter
def initialize
namegetter = NameGetter.new
name = namegetter.name
puts "How do you feel?"
feelings = gets.chomp
puts "Well, #{name}, sounds like you're feeling #{feelings}"
end
end #class

nfg = NameAndFeelingGetter.new
###############

then run the program...

happy ruby-ing...

-j
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top