This question is about code style.

I have this line in one of my models:

has_many :owning_artists, :through => :artist_tracks, :source => :artist, :conditions => { :artist_tracks => { :artistic_role_id => 1, :another_memeber => 42 } }

What is the best way to break this up on multiple lines, and indented of course, and what would it would look like?

I'd love to hear a more general recommendation/guideline for how to break up and indent nested hashes too.


This is what I would do:

has_many :owning_artists, {
  :through => :artist_tracks,
  :source => :artist,
  :conditions => {
    :artist_tracks => {
      :artistic_role_id => 1,
      :another_memeber => 42
  • 1
    \$\begingroup\$ Can't really add to this other than to say that if the artist_tracks hash had more than one member I would break those on to individual lines as well, indented accordingly. \$\endgroup\$
    – Robin Fisher
    Feb 26 '13 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.