【问题标题】:Invocation in ruby without a method name [duplicate]在没有方法名称的情况下调用 ruby​​ [重复]
【发布时间】:2015-10-19 19:47:42
【问题描述】:

在我的 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

【问题讨论】:

  • 谢谢@Drenmi,我想不出一个好的搜索词组。它是重复的。
  • 没问题@max。由于缺少方法名称,因此需要进行一些搜索才能找到。 :-)

标签: ruby-on-rails ruby guard


【解决方案1】:

试试:

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

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

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    相关资源
    最近更新 更多