Created
March 8, 2012 10:44
-
-
Save ku1ik/2000357 to your computer and use it in GitHub Desktop.
Line breaking in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1 | |
# Lets assume following line is longer than 80 cols and I want it to break it | |
Foobar.some_method.another_on(:with_some => :arg, :and_another => "one") | |
# Variant 1 | |
Foobar.some_method.another_on( | |
:with_some => :arg, :and_another => "one" | |
) | |
# Variant 2 | |
Foobar. | |
some_method. | |
another_on(:with_some => :arg, :and_another => "one") | |
# Variant 3 | |
Foobar.some_method.another_on(:with_some => :arg, | |
:and_another => "one") | |
# Variant 4 | |
Foobar.some_method.another_on(:with_some => :arg, | |
:and_another => "one") | |
# What would you do? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 2 | |
# Lets assume following line is longer than 80 cols and I want it to break it | |
@asciicasts = Asciicast.order("created_at DESC").page(params[:page]).per(PER_PAGE) | |
# Variant 1 | |
@asciicasts = Asciicast. | |
order("created_at DESC"). | |
page(params[:page]). | |
per(PER_PAGE) | |
# Variant 2 | |
@asciicasts = Asciicast.order("created_at DESC").page(params[:page]). | |
per(PER_PAGE) | |
# Variant 3 | |
@asciicasts = | |
Asciicast.order("created_at DESC").page(params[:page]).per(PER_PAGE) | |
# Variant 4 | |
@asciicasts = Asciicast.order("created_at DESC").page(params[:page]) \ | |
.per(PER_PAGE) | |
# What would you do? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 3 | |
# Lets assume following line is longer than 80 cols and I want it to break it | |
Foobar.some_method.another_on(positional_arg, :with_some => :arg, :and_another => "one", :foo => "barbazzz") | |
# Huh, now what? :P |
@psionides +1, that's also the recommended scala style. We're using it in our projects and it's really nice to read :)
@psionides @ktoso: see line_break3.rb also, it's more challenging ;)
same thing, break line after (
and each ,
. Consistency in style is important, there's no "what about this case?" ;)
Either as @ktoso says or leave positional_arg
in the first line and then each key-value pair on a new line.
Agree on guys opinions above; one note from myself is I really hate breaking lines like in examples:
File 1: variant 3
File 2: variant 1 (what determines indentation here?), 2, 4
Nesting is two spaces per level. Period.
+1 @psionides. I do that in JS as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File 1: variant 1 if I had to choose, but I'd rather do:
File 2: variant 1 or 2, but first I'd try to do anything to avoid that, e.g.