Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Newline in Ruby

This is a very... newbish question, one might say. I'm wondering how to separate hideously long lines of code into several smaller lines of code. You see, I'm used to semicolon syntax. In that case, you simply omit the semicolon. But I'm not sure what to do with Ruby.

Whenever I tried to google for my answer, I would always get information related to '\n'. :D
 
In ruby, you can just hit ENTER/RETURN after a special character. IE: ,, +, -, *, /, (, %, etc.
Nphyx, Ruby's syntax is the most beautiful syntax I've ever seen. And I've seen some VERY ugly syntax in my days.
 
You can also use the standard antislash :

Code:
string = 'this is' + \
'a string'

Ruby, ugly ? I have to disagree. No semicolon needed, no braces after 'if', you can forget parenthesis, variable prefixes only needed if you need to change the scope of these, indentation is purely for the beauty of the thing, similarities between functions and variables (if you used $foo.bar, you can make a bar function to replace a bar variable)... Ruby rocks.
 

___

Sponsor

rataime;213568 said:
You can also use the standard antislash :

Code:
string = 'this is' + \
'a string'

Ruby, ugly ? I have to disagree. No semicolon needed, no braces after 'if', you can forget parenthesis, variable prefixes only needed if you need to change the scope of these, indentation is purely for the beauty of the thing, similarities between functions and variables (if you used $foo.bar, you can make a bar function to replace a bar variable)... Ruby rocks.

Ruby's definitely cool, but coming from a background of C-based languages I have that syntax ingrained not only as an annoying neccessity but as a visual queue that helps me read the code. It's taking me a while to see the beginning of a conditional statement and an 'end' on the same indentation as a block. I really like the use of symbols to differentiate and initialize different variable scopes but once again it looks like clutter to the eye trained to look for things like 'local int' and 'global bool'. So I'll probably get used to it as I understand it and practice it more but it really is tough to digest : ) I had the same problem with Lua and ended up never learning much about it, but Ruby has some obvious advantages I am interested in exploring (implicit iterators, zomg).
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top