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
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

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