Question: Does Ruby use semicolon


#1


Question: Does Ruby use semicolon and why/why not? I know that JavaScript uses them and when I do use them in Ruby in the CodeCademy editor it does work. :slight_smile:


#2

No, it does not. Why not? Can't honestly say other than the author wanted the language to be simple (in essence) and concise.


#3

So I guess I found a bug in your editor then. To be exact, the editor accepts your code even when your add a semicolon. It doesn't show any syntax error which I assume it should.


#4

Show us your code please, as well as a link to the exercise. Thanks.


#5

The exercise is 3. Variables in Intro to Ruby the code is here:


my_num = 100;

It's pretty simple but it works somehow.


#6

Just in case.


I even entered 2,3 and 4 semicolons, no error.


#7

Can't say for sure but Ruby could be ignoring the token. Might need to do some reading on that.


#8

Should I report it as a bug for other moderators/admins to see it???


#9

I don't see it as a bug if it is not raising any console errors (Ruby syntax). Just know that you don't need to use the tokens.

http://www.caliban.org/ruby/rubyguide.shtml#semicolon

Ruby allows the use of the semi-colon as a statement separator. This means you can place one at the end of a line and also use it as a way to put multiple statements on a single line. Don't do this. A semi-colon at the end of the line is superfluous and placing multiple statements on one line decreases the legibility of your code.


#10

Alright, thanks! However before you go I also have a question about JavaScript. I'm pretty sure other people may have spotted this but when you don't put a semicolon on a line of code it doesn't raise any syntax errors. Also sorry this is irrelevant to Ruby.


30. What are objects for
#11

Javascript will permit single statements with only a newline, and no semi-colon. However if the code is ever minimized the tokens will need to be inserted else the code will be invalid. We put the semi-colons to permit multiple statements on one line. JS Linters will flag code with a caution, but not a warn if the token is left off. That means it will still run. Ruby linters will not flag lines without them since it is the typical usage..

Extra reading. JS auto-insertion of semi-colon at end of statement.


#13

Thanks, @mtf! :grinning:


#14