Breaking Down the Syntax
Now that we know how to build a minimal Cuba application, let's take a deeper look at the syntax. We can split this example into three parts:
First, we require Cuba to load the gem and get access to its functionality.
require "cuba"
Then we can identify four methods that appear in most Cuba
applications: define, on, root and res.
Cuba.define do
on root do
res.write("Hello, Cuba!")
end
end
defineallows us to create an application through a block.onexecutes a given block if the passed conditions evaluate totrue.rootreturnstrueif the accessed path is the root of the application ("/"or"").reshandles the server response. In this case, we use thewritemethod to set the response body with the greeting message.
Finally, the last line connects our application with Rack.
run(Cuba)
Don't worry if you don't understand what Rack is just yet, we'll discuss it in the next section.