krunal shah
krunal shah

Reputation: 16339

Can i pass method name as argument with super?

I have created a common controller for my application.

class CommonController < ApplicationController
  def index 
   # My stuff
  end
end

And in my other controller i am using super to call my index method like this.

class Other1Controller < CommonController
  def index
    super
  end
end

class Other2Controller < CommonController
  def index
    super
  end
end

This is working fine.

Now in my class i have two method index and 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

Is there any way ? can i pass method with super to override my method with specific method?

Upvotes: 0

Views: 361

Answers (1)

mipadi
mipadi

Reputation: 411270

Why not just call index?

class Other1Controller < CommonController
  def index
    super
  end

  def index1
    index
  end
end

Upvotes: 5

Related Questions