DEV Community

loading...

Discussion on: Which is more readable?

Collapse
gene profile image
Gene

I prefer this solution as well. It's simple and clear. Easy to understand.

json_data = {
  user: add_user_data(mentioner)
}

if mentionable_type == "Comment"
  json_data[:comment] = add_comment_data(mentionable) 
end
Collapse
richjdsmith profile image
Rich Smith

My preference goes with this one as well. Declaring json_data = {} in advanced just isn't necessary for writing code that is easy to be able to follow along with.