-1

出现错误:./http.rb:13: # (NoMethodError) 的未定义方法“代码”

#!/usr/bin/ruby

require 'rubygems'
require 'httparty'

class Foo
  include HTTParty
end

# Simple get with full url
r = Foo.get('http://www.google.com/')

p r.code
4

1 回答 1

0

Include HTTParty 也将指定模块的方法代码添加到 Foo 类中。见混音

module HTTParty
  module AllowedFormatsDeprecation
    def get
      #...
    end
  end
end

将 HTTParty 混入 Foo 应该可以工作

于 2013-04-19T13:50:12.097 回答