未定义的方法与sinatra

时间:2010-05-20 22:49:06

标签: ruby sinatra

我有以下代码

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

1 个答案:

答案 0 :(得分:11)

是否有可能在您运行的文件所在的文件夹中有名为“sinatra.rb”的文件? “要求”首先检查本地目录 ,所以如果那里有一个,它就不会找到真正的宝石。

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