This project is archived and is in readonly mode.

#589 ✓wontfix
Ruy Asan

:args option for run_callbacks

Reported by Ruy Asan | July 10th, 2008 @ 01:34 AM | in 2.x

Patch attached, here's the branch

#   * +:args+ - Pass the provided arguments array to each callback method or proc.
#     Arguments that exeed the arity of the callback method/proc will be silently
#     discarded rather then generate a warning. String callbacks cannot receieve
#     arguments. (default: +[]+ i.e. no arguments will be passed)

Example:

  def investigate(suspect)
    run_callback :before_investigation, :args=>[suspect]
    # ...
    run_callback :after_investigation, :args=>[suspect]
  end
  
  before_investigation :plant_evidence
  after_investigation :testify_in_court

  def plant_evidence(suspect)
    suspect.plant(INCRIMINATING_STUFF)
  end
  
  def testify_in_court
    # ... 
    # Note i don't need to expect the (suspect) arg if I'm not going to use it
  end
end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages