re: Which is more readable? VIEW POST


Second and maybe with the function calls extracted into variables.


Yeah, leaning toward the second one, too. I like the variable idea.


I think I misunderstood what you were trying to do though. If you are trying to do conditional assignment then I like what @rhymes said. You can set missing keys to nil and then filter them out

user = add_user_data(mentioner)
comment = mentionable_type == "Comment" ?
  add_user_data(mentioner) : nil
json_data = { user: user, comment: comment }.reject { |_, v| v.nil? }
code of conduct - report abuse