Search code examples
ruby-on-railsrubyguard

Invocation in ruby without a method name


In my Guardfile I have this strange method invocation syntax rspec.spec.("requests/#{m[1]}"). While this works perfectly I don't understand is what method is actually being called.

Is there a name or term for this syntax?

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

Solution

  • Try:

    foo = "Foo"
    foo.("a")
    # NoMethodError: undefined method `call' for "Foo":String
    
    routine = Proc.new { |arg| puts "Hello #{arg}!" }
    routine.("world")
    # Hello world!