user178391
user178391

Reputation: 11

*args and methods that expect a specific number of arguments

instead of this

module ActionView
  module Helpers
    module FormHelper
      def text_area_with_wrap(object_name, method, options)
        "<span class=\"wrap\">#{text_area_without_wrap(object_name, method, options)}</span>"
      end
      alias_method_chain :text_area, :wrap
    end
  end
end

for obvious reasons I would want to do this

module ActionView
  module Helpers
    module FormHelper
      def text_area_with_wrap(*args)
        "<span class=\"wrap\">#{text_area_without_wrap(args)}</span>"
      end
      alias_method_chain :text_area, :wrap
    end
  end
end

Does any of you know if and how this can be done? Can't find it in the manuals.

Many thanks in advance!

Upvotes: 1

Views: 1315

Answers (1)

Christoph Schiessl
Christoph Schiessl

Reputation: 6868

I think this should work:

module ActionView
  module Helpers
    module FormHelper
      def text_area_with_wrap(*args)
        "<span class=\"wrap\">#{text_area_without_wrap(*args)}</span>"
      end
      alias_method_chain :text_area, :wrap
    end
  end
end

Note the extra *.

Upvotes: 3

Related Questions