我正在尝试ex:50 of learning Ruby the hard way。这涉及到使用“sinatra”创建hello\u world应用程序。
我犯了如下错误:

 ruby lib/gothonweb.rb
    lib/gothonweb.rb:5:in `<module:Gothonweb>': undefined method `get' for Gothonweb:Module             (NoMethodError)
    from lib/gothonweb.rb:4:in `<main>'

最佳答案

这不是你做过的事,给定的代码不起作用:

require_relative "gothonweb/version"
require "sinatra"

module Gothonweb
  get '/' do
    greeting = "Hello, World!"
    return greeting
  end
end

这不起作用,因为它被封装在一个模块中试试这个:
require_relative "gothonweb/version"
require "sinatra"

get '/' do
  greeting = "Hello, World!"
  greeting # there's no need for the return here,
           # the last expression is the return value
end

关于ruby - 练习50::http://ruby.learncodethehardway.org/book/ex50.html(使用sinatra运行hello world时出错”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16645762/

10-12 01:34