read

Assignment & Then Some

I recently ran across a rather odd looking bit of Ruby while browsing the Database Cleaner readme.

DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}

That looks really wierd to me. Assignment, with some additional parameters. Odd, but after looking at it, it makes sense what they are doing.

def strategy=(args)
  arg, *params = args
  puts "#{arg} with some params of #{params}"
end

Neat, but I don't know if I like it when using the = operator. For one thing, the params must be enclosed in {}.

Besides that, it just looks really wierd.

While a clever trick to add some additional information to an attribute, I find it confusing, but I don't really have a bettersolution.

Blog Logo

Mark Borcherding


Published

Image

Fooberry

Sweetness without context

Back to Overview