2

私は、「sinatra」を使用してhello_worldアプリケーションを作成することを含む、Rubyを難しい方法で学習するex:50を試しています。次のようなエラーが発生します。

 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>'
4

1 に答える 1

2

それはあなたがやったことではありません。与えられたコードは機能しません:

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
于 2013-05-21T00:25:36.013 に答える