Home arrow Ruby-on-Rails arrow Page 2 - Ruby for the Newbie
RUBY-ON-RAILS

Ruby for the Newbie


In last week's article, we installed Ruby on Rails the easy way, by first installing Ruby, then installing Rails. In this article, the second part of a six-part series, we'll actually do something with what we installed. We'll start with an offbeat version of the Hello World program, and move forward from there.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 15, 2007
TABLE OF CONTENTS:
  1. · Ruby for the Newbie
  2. · A Few Notes About Formatting
  3. · Variables
  4. · Constants

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Ruby for the Newbie - A Few Notes About Formatting
(Page 2 of 4 )

Let's say you don't want to write puts on each line when writing your text to the screen. There are a few options for this:


print "I like hamburgers. nThey are good" # sorry, I'm hungry

The above code would display:

  I like hamburgers.

  They are good.

The n tells the program to skip to the next line. You can also use the <<Whatever document.

<Note: You don't have to use the word Whatever; any word is acceptable>


print <<WHATEVER

I like hamburgers.

They are good.

WHATEVER

This would result in the same text as our previous example:

  I like hamburgers.

  They are good.

In addition to typing in the quotes (" ") yourself, you can let Ruby add them for you. For single quotes use %q, for double quotes use %Q.


puts %Q/I like apples/

puts %q/Me too/

The above code would display the following text:

  "I like apples"

  'Me too'

You can also concatenate (or join together) strings very simply in Ruby, using the + symbol.


puts "Come over here" + "now"

Would print out: "Come over here now."


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials