When learning Ruby, I noticed that in all the examples there are no semicolons. I am aware that this is perfectly fine as long as each statement is on its own line. But what I am wondering is, can you use semicolons in Ruby?
C# makes use of Semicolon to get rid of ambiguity and confusion as its usage makes the code clear, structured and organised. Like other languages especially C and C++, C# also follows the same rules in the Semicolon application. The absence of Semicolon throws an error by the compiler which has to be rectified.
Semicolons. Unlike many other languages, Swift doesn't require you to write a semicolon ( ; ) after each statement in your code, although you can do so if you wish. However, semicolons are required if you want to write multiple separate statements on a single line: let cat = "🐱"; print(cat)
Python does let you use a semicolon to denote the end of a statement if you are including more than one statement on a line. Show activity on this post. Multiple statements on one line may include semicolons as separators. For example: 8.
The semicolon is treated as the end of line statement. It treats it as the end of the expression, if not the expression can continue to the next line. But, in Scala, the end of the line is treated as the end of the expression. This means the user does not need to compulsorily use the semicolon (;) statement.
Yes.
Ruby doesn't require us to use any character to separate commands, unless we want to chain multiple statements together on a single line. In this case, a semicolon (;) is used as the separator.
Source: http://articles.sitepoint.com/article/learn-ruby-on-rails/2
As a side note, it's useful to use semi-colons in your (j)irb session to avoid printing out a ridiculously long expression value, e.g.
irb[0]> x = (1..1000000000).to_a [printout out the whole array]
vs
irb[0]> x = (1..100000000).to_a; nil
Nice especially for your MyBigORMObject.find_all calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With