Snippet of code:
require "./name.rb";
require "./feelings.rb";
puts "Hello, " + name
How do I get the class(object) from name.rb?
···
--
Posted via http://www.ruby-forum.com/.
Snippet of code:
require "./name.rb";
require "./feelings.rb";
puts "Hello, " + name
How do I get the class(object) from name.rb?
--
Posted via http://www.ruby-forum.com/.
Maybe I'm misunderstanding what you're trying to do. The Ruby interpreter
won't have any variable called name in this program simply because you've
required a file called name.rb. Assuming that your name.rb file has a class
in it called Name, you would be able to require the file, create a new
instance of Name and assign it to a variable called name, and then use it as
you're trying to.
# name.rb
class Name
attr_accessor :first, :last
def to_s
@first + " " + @last
end
end
# main program
require "./name"
name = Name.new("Some", "Guy")
puts "Hello, " + name
On Tue, Feb 22, 2011 at 1:01 AM, Anthony Ob <vidgametester@gmail.com> wrote:
Snippet of code:
require "./name.rb";
require "./feelings.rb";
puts "Hello, " + nameHow do I get the class(object) from name.rb?
--
Posted via http://www.ruby-forum.com/\.
Ok, nvm that last post, How do I call classes from other scripts?
--
Posted via http://www.ruby-forum.com/.