我可以将方法名称作为参数传递给super吗?

时间:2010-10-15 20:03:04

标签: ruby-on-rails ruby

我为我的应用程序创建了一个通用控制器。

class CommonController < ApplicationController
  def index 
   # My stuff
  end
end

在我的其他控制器中,我使用super来调用我的索引方法。

class Other1Controller < CommonController
  def index
    super
  end
end

class Other2Controller < CommonController
  def index
    super
  end
end

这很好。

现在我的课程中有两个方法索引和index1。

class Other1Controller < CommonController
  def index
    super
  end

  def index1
    super(index) # Can i pass method inside super to override this method with my 
                 # common index method.
  end
end

有什么办法吗?我可以用super传递方法来用特定方法覆盖我的方法吗?

1 个答案:

答案 0 :(得分:5)

为什么不拨打index

class Other1Controller < CommonController
  def index
    super
  end

  def index1
    index
  end
end