在没有方法名称的情况下调用ruby

时间:2015-10-19 11:43:23

标签: ruby-on-rails ruby guard

在我的Guardfile中,我有这种奇怪的方法调用语法rspec.spec.("requests/#{m[1]}")。虽然这很有效但我不明白实际调用的是什么方法。

此语法是否有名称或术语?

guard :rspec, cmd: "bundle exec rspec" do

  # ...
  watch(rails.controllers) do |m|
    [
      rspec.spec.("routing/#{m[1]}_routing"),
      rspec.spec.("controllers/#{m[1]}_controller"),
      rspec.spec.("requests/#{m[1]}")
    ]
  end
end

1 个答案:

答案 0 :(得分:3)

尝试:

foo = "Foo"
foo.("a")
# NoMethodError: undefined method `call' for "Foo":String

routine = Proc.new { |arg| puts "Hello #{arg}!" }
routine.("world")
# Hello world!