Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created March 8, 2012 10:44
Show Gist options
  • Save ku1ik/2000357 to your computer and use it in GitHub Desktop.
Save ku1ik/2000357 to your computer and use it in GitHub Desktop.
Line breaking in Ruby
# 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?
# 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?
# 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
@mariusz
Copy link

mariusz commented Mar 22, 2012

+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