你如何使用不同文件中的类?

Chr*_*own 3 ruby

我正在尝试使用来自不同文件的类.

something.rb

class Something
  def initialize
  end
  def getText
    'Some example text'
  end
end
Run Code Online (Sandbox Code Playgroud)

another.rb

class Another
end

somethingVar = Something.new
puts somethingVar.getText
Run Code Online (Sandbox Code Playgroud)

这给了我错误

/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/chris/RubymineProjects/untitled1/another.rb
/home/chris/RubymineProjects/untitled1/another.rb:4:in `<top (required)>': uninitialized constant Something (NameError)
    from -e:1:in `load'
    from -e:1:in `<main>'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

B S*_*ven 5

你必须要求something.rb.

require 'something.rb'
Run Code Online (Sandbox Code Playgroud)