views:

28

answers:

1

Hey folks,

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 nay of you know if and how this can be done? Can't find it in the manuals.

Many thanks in advance!

+3  A: 

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 *.

Christoph Schiessl
As I understand it, `*args` in a method definition sucks all the remaining parameters into a single array, and `*args` elsewhere expands a single array into all its elements.
glenn jackman
Exactly. `*args` is always the last parameter of a given method and consumes all the remaining arguments.
Christoph Schiessl