Ruby-on-Rails
  Home arrow Ruby-on-Rails arrow Page 2 - Ruby for the Newbie
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
RUBY-ON-RAILS

Ruby for the Newbie
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-10-15

    Table of Contents:
  • Ruby for the Newbie
  • A Few Notes About Formatting
  • Variables
  • Constants

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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."

    More Ruby-on-Rails Articles
    More By James Payne


       · Before I comment, I just want to give you guys a brief heads-up: For some reason the...
       · Great article, James Payne "Gorilla Lord!" :)A couple of suggestions:1) This...
       · Hi Farsheed,Thanks for the comments. The sites are presently being redesigned,...
       · Well frankly, I have absolutely no idea how or where to begin. I'm more of a...
       · Hey! I finally found a solution to my problem regarding working in Shell and...
       · Hey Farsheed,Thanks for posting the solution. I have to agree with you regarding...
       · Hello James!As you can probably see, I finally created an account! I figured it...
     

    RUBY-ON-RAILS ARTICLES

    - Iterating and Incrementing Strings in Ruby
    - Comparing and Manipulating Strings in Ruby
    - Strings in Ruby
    - Ruby On Rails: Making Your First Dynamic Site
    - Ruby on Rails: Beginning Rails
    - Ruby: Modules, Mixins, Fixins, and Rails
    - Controlling Information Access with the Rail...
    - URLs, Filters and the Rails Action Controller
    - Flash and the Rails Action Controller
    - Rails Action Controller
    - Dropping and Sorting with AJAX and script.ac...
    - Drag and Drop with script.aculo.us and Rails
    - Introducing script.aculo.us
    - Ruby Classes and Objects
    - Ruby Loops






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT