为什么我得到错误未初始化的常量Stuff :: HTTParty?

Mic*_*ant 6 ruby methods gem class httparty

我的系统上有HTTParty gem,我可以在rails中使用它.

现在我想独立使用它.

我在尝试:

class Stuff
  include HTTParty
  def self.y
    HTTParty.get('http://www.google.com')
  end 
end
Stuff.y
Run Code Online (Sandbox Code Playgroud)

但我明白了

$ ruby test_httparty.rb 
test_httparty.rb:2:in `<class:Stuff>': uninitialized constant Stuff::HTTParty (NameError)
        from test_httparty.rb:1:in `<main>'
07:46:52 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker 73845718_get_method
$ 
Run Code Online (Sandbox Code Playgroud)

Ste*_*fan 15

你必须require 'httparty':

require 'httparty'

class Stuff
  include HTTParty
  # ...
end
Run Code Online (Sandbox Code Playgroud)