I have a model with an initializer in it, which basically creates a user from a user hash.
After it gets the user information, it checks whether the "privileges" key in the hash is an array. If it's not, it turns it into an array.
Now the obvious way of doing this would be crafting an entire user_hash so that it would skip those "create user" lines and then check if it turns the input into an array if necessary. However, I was wondering if there is a more DRY way of doing this?
Here is the user model I'm talking about:
def initialize(opts={})
@first_name = opts[:user_hash][:first]
@last_name = opts[:user_hash][:last]
@user_name = opts[:user_hash][:user_name]
@email = opts[:user_hash][:email]
@user_id = opts[:user_hash][:id]
@privileges = {}
if opts[:privs].present?
if !opts[:privs].kind_of?(Array)
opts[:privs] = [opts[:privs]]
end
end
end
opts[:privs]used somewhere?