Ruby 意式浓缩咖啡

Ruby 意式浓缩咖啡,ruby,Ruby,使用Sinatra,我可以通过以下方式将多个“未知”参数传递给路由: get '/say/*/to/*' do # matches /say/hello/to/world params[:splat] # => ["hello", "world"] end 如何在浓缩咖啡中做到这一点?浓缩咖啡中的路线是常规的Ruby方法 因此,如果该方法在Ruby中工作,那么该路线将在Espresso中工作 Ruby免费提供您想要实现的目标 只需使用预定义参数定义Ruby方法: require

使用Sinatra,我可以通过以下方式将多个“未知”参数传递给路由:

get '/say/*/to/*' do
  # matches /say/hello/to/world
  params[:splat] # => ["hello", "world"]
end

如何在浓缩咖啡中做到这一点?

浓缩咖啡中的路线是常规的Ruby方法

因此,如果该方法在Ruby中工作,那么该路线将在Espresso中工作

Ruby免费提供您想要实现的目标

只需使用预定义参数定义Ruby方法:

require 'e'

class App < E
  map '/'

  def say greeting = :hello, vertor = :to, subject = :world
    "say #{greeting} #{vertor} #{subject}"
  end
end

# some testing
require 'sonar' # same as rack-test but a bit better
include Sonar

app App # letting Sonar know that app to test

puts get('/say').body
# => say hello to world

puts get('/say/Hi').body
# => say Hi to world

puts get('/say/Hi/from').body
# => say Hi from world

puts get('/say/Hello/from/Espresso').body
# => say Hello from Espresso

puts get('/say/Goodbye/to/Sinatra').body
# => say Goodbye to Sinatra
需要“e”
类App向世界问好
放置get('/say/Hi')。主体
#=>向世界问好
将get('/say/Hi/from').body
#=>向世界问好
将get('/say/Hello/from/Espresso').body
#=>用浓缩咖啡打招呼
将get('/say/再见/to/Sinatra').body
#=>向西纳特拉说再见

哇,太棒了!不再使用DSL!只有红宝石,只有硬核!多谢各位!