Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-16-2003, 07:20 PM   #1 (permalink)
do_guh_new
Registered User
 
do_guh_new's Avatar
 
Join Date: Jun 2002
Location: Ormond Beach Florida
Posts: 16
do_guh_new is on a distinguished road
Send a message via Yahoo to do_guh_new
beginings of ruby

explanation of the language and a simple example

There are many things to like about this little used language. (at least over here in japan it's been a widly popular since the mid '90's) Ruby is simple and concise with a simple syntax you can get a lot done with a remarkably short program. It's totally object-oriented; everything is an object or can be made into an object. And of course the first rule of writing about languages is that the first example must be a "Hello, World!" program, so here it is:

Code:
puts "Hello, World. Time: #{Time.now}"
explanation:

Ruby has a built in method called puts(). It writes its argument to standard output and appends a newline if there isnt one already. The cool thing is the #{Time.new} stuff. If Ruby finds the construct #{expr} in double quoted strings, it evaluates the enclosed expression then converts the result to a string and subsitutes that back into the original. The expression can be anything from a simple variable to a sizable block of code. In the above case the expression is a call to the now() method of the class Time, which returns a new Time object initialized to the current time. When converted to a string, time objects look comfortingly familiar, so if we ran this code, the puts() method would send the string to standard output and we would see output like the following:

Code:
Hello, World. Time: Sat Jun 15 24:24:54 EST 2002
do_guh_new is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby? Apodysophilia All Other Coding Languages 5 03-26-2004 05:55 AM
Ruby tutorials ntws01 All Other Coding Languages 1 03-19-2003 12:50 AM


All times are GMT -8. The time now is 03:55 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting