text stringlengths 0 444 |
|---|
Lorem Ipsum is simply dummy text of the printing and typesetting industry. |
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, |
when an unknown printer took a galley of type and scrambled it to make a type specimen book. |
LOREM |
# good |
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. "\ |
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, "\ |
"when an unknown printer took a galley of type and scrambled it to make a type specimen book." |
---- |
== Heredocs |
=== Squiggly Heredocs [[squiggly-heredocs]] |
Use Ruby 2.3's squiggly heredocs for nicely indented multi-line strings. |
[source,ruby] |
---- |
# bad - using Powerpack String#strip_margin |
code = <<-RUBY.strip_margin('|') |
|def test |
| some_method |
| other_method |
|end |
RUBY |
# also bad |
code = <<-RUBY |
def test |
some_method |
other_method |
end |
RUBY |
# good |
code = <<~RUBY |
def test |
some_method |
other_method |
end |
RUBY |
---- |
=== Heredoc Delimiters [[heredoc-delimiters]] |
Use descriptive delimiters for heredocs. |
Delimiters add valuable information about the heredoc content, and as an added bonus some editors can highlight code within heredocs if the correct delimiter is used. |
[source,ruby] |
---- |
# bad |
code = <<~END |
def foo |
bar |
end |
END |
# good |
code = <<~RUBY |
def foo |
bar |
end |
RUBY |
# good |
code = <<~SUMMARY |
An imposing black structure provides a connection between the past and |
the future in this enigmatic adaptation of a short story by revered |
sci-fi author Arthur C. Clarke. |
SUMMARY |
---- |
=== Heredoc Method Calls [[heredoc-method-calls]] |
Place method calls with heredoc receivers on the first line of the heredoc definition. |
The bad form has significant potential for error if a new line is added or removed. |
[source,ruby] |
---- |
# bad |
query = <<~SQL |
select foo from bar |
SQL |
.strip_indent |
# good |
query = <<~SQL.strip_indent |
select foo from bar |
SQL |
---- |
=== Heredoc Argument Closing Parentheses [[heredoc-argument-closing-parentheses]] |
Place the closing parenthesis for method calls with heredoc arguments on the first line of the heredoc definition. |
The bad form has potential for error if the new line before the closing parenthesis is removed. |
[source,ruby] |
---- |
# bad |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.