Instance_eval block not supplied? [duplicate]

2019-01-29 12:35发布

This question already has an answer here:

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条回答
做自己的国王
2楼-- · 2019-01-29 12:57

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

run(Cherry.app do
    "Hello World"
end)
查看更多
登录 后发表回答