What's a more idiomatic Ruby way of writing this?

idioms, ruby, syntax

Solution

That looks perfectly reasonable to me. You could move the assignment in front of the if ( `parent_id = if params...`) or use the ternary, but I don't think the result would look better.

If parent_id is nil or undefined before that line you can simply write:

parent_id = params[:parent_id] unless params[:parent_type] == "Order"

Problem

``` if params[:parent_type] == "Order" parent_id = nil else parent_id = params[:parent_id] end ``` Would a Ruby person laugh at me for writing it this way? It doesn't seem particularly concise like some Ruby code I've seen.

Original source