In fact, Ruby distinguishes between line breaks and whitespace.

I see some stories that "Ruby doesn't distinguish between line breaks and whitespace" [^ space]. That's not the case.

[^ space]: The "blank" here is the so-called "half-width space" (U + 0020).

If line breaks and whitespace are indistinguishable

x = 1 puts x

You should see 1, but you get a SyntaxError. That's no surprise. Also,

puts
1

Should display 1, but only line breaks are output. That's no surprise.

Ruby is rather a language that distinguishes between line breaks and whitespace. That is why the semicolon at the end of the sentence can be omitted.

Why did it spread?

Ruby on Rails Tutorial 4th Edition "4.3.4 CSS, Again" https://railstutorial.jp/chapters/rails_flavored_ruby?version=5.0#sec-css_revisited To

In fact, Ruby doesn't distinguish between line breaks and whitespace

There is a crap [^ latest]. Is this the source? !!

[^ latest]: I don't know what's going on with the latest version (because it's paid).

I think the Ruby on Rails tutorial is a really good tutorial. The quality of the Japanese translation is quite high, and I am grateful to the authors and translators. For that reason, I regret why such a rudimentary error was written.

Recommended Posts

In fact, Ruby distinguishes between line breaks and whitespace.
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
[Understanding] Differences between hashes and arrays in Ruby
The difference between puts and print in Ruby is not just the presence or absence of line breaks
Differences between Ruby syntax error statements in Ruby and binary
String concatenation and line breaks
About the difference between "(double quotation)" and "single quotation" in Ruby
Handling of line beginning and line ending in regular expressions in Ruby
Remove consecutive line breaks and tabs before and after in Java
[Ruby] Difference between get and post
[Ruby] Difference between is_a? And instance_of?
[Ruby] then keyword and case in
Write keys and values in Ruby
Difference between final and Immutable in Java
Make bubble sort and selection sort in Ruby
Difference between Ruby instance variable and local variable
Difference between pop () and peek () in stack
Summary of hashes and symbols in Ruby
Difference between getText () and getAttribute () in Selenium
[Ruby] Classification and usage of loops in Ruby
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
[Ruby] Difference between print, puts and p
Differences between Ruby strings and symbols [Beginner]
Difference between int and Integer in Java
[Ruby] Difference between methods with and without self in the class. About class methods and instance methods.
Read and write line by line from buffer with TCP communication between C and Ruby
Difference between next () and nextLine () in Java Scanner
Put CSV files containing "'" and "" "in MySQL in Ruby 2.3
[Ruby] Difference between puts and return, output and return value
Distinguish between positive and negative numbers in Java
Ruby: Differences between class methods and instance methods, class variables and instance variables
Ruby How to convert between uppercase and lowercase
Just put `clang 12.0.0` in macOS` Catalina` and put `ruby 3.0.0`