2012-08-29 39 views
0

有谁知道是什么原因导致了这个错误?我正在尝试制作基本的机架应用程序。Instance_eval块未提供?

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 

编辑:显然,我忘了,包括错误woops:

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

+0

这是[红宝石块语法错误(http://StackOverflow.Com/q/6854283/),[代码块中传递重复,以'each'作品用括号括起来,但不用'do' -'end'(ruby)](http://StackOverflow.Com/q/6718340/),[块定义 - 大括号和''''''end'之间的区别?](http ://StackOverflow.Com/q/6179442/),[没有'do''end的Ruby多行块]](http://StackOverflow.Com/q/3680097/),[使用'do'块vs括号'{ } [](http://StackOverflow.Com/q/2122380/),[Ruby中这些块编码风格的区别或价值是什么?](http://StackOverflow.Com/q/533008/),... –

+0

... [Ruby block and unparenthesized arguments](http://StackOverflow.Com/q/420147/),[为什么'do' /'end'和'{}'总是等价的?](ht tp://StackOverflow.Com/q/7487664/),[Ruby块中的Wierd不完美](http://StackOverflow.Com/q/7620804/)和[将块传入方法 - Ruby](http:///StackOverflow.Com/q/10909496/)。 –

回答

0

定了!显然,你需要周围的Cherry.app do..块括号:

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