I love keyword arguments when they were introduced in Ruby 2.0, and use them every chance I get. As I was hacking around with ActiveJob today, and thought it would be cool to pass keyword arguments into the ActiveJob#perform_later method.
I thought it should work. It didn’t.
class MyAwesomeJob < ActiveJob::Base
def perform(ginger_ninjas: 1)
You get an ArgumentError: wrong number of arguments (1 for 0) error. The reason is the hash is converted to string keys upon serialization.
So I was thrilled when I did a bit of searching to see if anyone else had the same issue. Nope. Looked at the ActiveJob::Arguments module. Passing keyword arguments are not supported. I actually get to report a real feature request to Rails!
This this is where the magic began… within a few minutes Sean Griffin (@sgrif) picked up on the issue report. I went to lunch, planning to fork ActiveJob and start hacking away when I got back. But Sean beat me to it. Sean added the ability to pass keyword arguments to ActiveJob jobs, and even backported it to Rails 4.2.1.
Within an hour, it was all done. Check out the full commit.
Want a reason to love Rails and their committers? This is one, of many.
Thank you Sean.