0

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)

andy
  • 2,369
  • 2
  • 31
  • 50
  • This is a duplicate of [Ruby Block Syntax Error](http://StackOverflow.Com/q/6854283/), [Code block passed to `each` works with brackets but not with `do`-`end` (ruby)](http://StackOverflow.Com/q/6718340/), [Block definition - difference between braces and `do`-`end` ?](http://StackOverflow.Com/q/6179442/), [Ruby multiline block without `do` `end`](http://StackOverflow.Com/q/3680097/), [Using `do` block vs brackets `{}`](http://StackOverflow.Com/q/2122380/), [What is the difference or value of these block coding styles in Ruby?](http://StackOverflow.Com/q/533008/), … – Jörg W Mittag Aug 29 '12 at 10:42
  • … [Ruby block and unparenthesized arguments](http://StackOverflow.Com/q/420147/), [Why aren't `do`/`end` and `{}` always equivalent?](http://StackOverflow.Com/q/7487664/), [Wierd imperfection in Ruby blocks](http://StackOverflow.Com/q/7620804/), and [Passing block into a method - Ruby](http://StackOverflow.Com/q/10909496/). – Jörg W Mittag Aug 29 '12 at 10:42

1 Answers1

0

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

run(Cherry.app do
    "Hello World"
end)
andy
  • 2,369
  • 2
  • 31
  • 50