Instance_eval block not supplied? [duplicate]

孤街醉人 提交于 2019-11-30 09:56:58

问题


Does anybody know what's causing this error? I'm trying to make a basic rack application.

App.rb =>

class Cherry
    class << self
        def app &block
            Cherry::Application.new &block
        end
    end

    class Application
        def initialize &block
            instance_eval &block
        end

        def print_start_message
            puts "Starting server"
        end

        def call env
            [200, {"Content-type" => "text/plain"}, "Hello World"]
        end
   end
end

Config.ru =>

   require 'app'

   run Cherry.app do
        print_start_message
   end

EDIT: Apparently I forgot to include the error woops:

/local/www/cherry/lib/app.rb:12:in 'instance_eval': block not supplied (ArgumentError)


回答1:


Fixed it! Apparently you need brackets around the Cherry.app do.. block:

run(Cherry.app do
    "Hello World"
end)


来源:https://stackoverflow.com/questions/12175788/instance-eval-block-not-supplied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!