How do I get the class(object) from another ruby script?

Snippet of code:

require “./name.rb”;
require “./feelings.rb”;
puts "Hello, " + name

How do I get the class(object) from name.rb?

Maybe I’m misunderstanding what you’re trying to do. The Ruby
won’t have any variable called name in this program simply because
required a file called name.rb. Assuming that your name.rb file has a
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.


class Name
attr_accessor :first, :last
def to_s
@first + " " + @last

main program

require “./name”
name =“Some”, “Guy”)
puts "Hello, " + name

Yeah, btw nvm I changed the code and dont need it anymore thanks

Ok, nvm that last post, How do I call classes from other scripts?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs