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
    ruby
  » beginings of ruby
      by do_guh_new
 Page 1 of 1 
   

(Login to remove green text ads)
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





 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle