sinatra 的未定义方法 get

发布于 2024-09-02 07:20:38 字数 1227 浏览 0 评论 0原文

我有以下代码

require 'rubygems'
require 'sinatra'

get '/' do
  'Hello World!'
end


gem list sinatra

*** LOCAL GEMS ***

sinatra (1.0, 0.9.4)


ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

错误

 ruby myapp.rb 
["==", "===", "=~", "__id__", "__send__", "class", "clone", "display", "dup", "enum_for", "eql?", "equal?", "extend", "freeze", "frozen?", "hash", "id", "include", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "method", "methods", "nil?", "object_id", "private", "private_methods", "protected_methods", "public", "public_methods", "respond_to?", "send", "singleton_methods", "taguri", "taguri=", "taint", "tainted?", "tap", "to_a", "to_enum", "to_s", "to_yaml", "to_yaml_properties", "to_yaml_style", "type", "untaint"]
./sinatra.rb:17: undefined method `get' for main:Object (NoMethodError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from myapp.rb:3

I have following code

require 'rubygems'
require 'sinatra'

get '/' do
  'Hello World!'
end


gem list sinatra

*** LOCAL GEMS ***

sinatra (1.0, 0.9.4)


ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

Error

 ruby myapp.rb 
["==", "===", "=~", "__id__", "__send__", "class", "clone", "display", "dup", "enum_for", "eql?", "equal?", "extend", "freeze", "frozen?", "hash", "id", "include", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "is_a?", "kind_of?", "method", "methods", "nil?", "object_id", "private", "private_methods", "protected_methods", "public", "public_methods", "respond_to?", "send", "singleton_methods", "taguri", "taguri=", "taint", "tainted?", "tap", "to_a", "to_enum", "to_s", "to_yaml", "to_yaml_properties", "to_yaml_style", "type", "untaint"]
./sinatra.rb:17: undefined method `get' for main:Object (NoMethodError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from myapp.rb:3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2024-09-09 07:20:38

您是否可能在与您正在运行的文件相同的文件夹中存在名为“sinatra.rb”的文件? “Require”首先检查本地目录,所以如果那里有,它就不会找到真正的 gem。

[1] https://sinatra.lighthouseapp.com/项目/9779/tickets/295-sinatra-hello-world-error

Is it possible that you have file named "sinatra.rb" in the same folder as the file you're running? "Require" checks the local directory first, so if there's one there, it won't go find the real gem.

[1] https://sinatra.lighthouseapp.com/projects/9779/tickets/295-sinatra-hello-world-error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文