Zamples, Inc. logo
 Home   Search   Solutions   My Zamples   FAQ   News   Contact 
Zamples ID:
Password:
   
0 anonymous users;
29 users logged in.

Live Samples
Live APIs

HTML or JSP Frag
Java Servlet Frag
HTML & Applet
Bash
C# (Mono)
C++ (gcc)
Groovy
Haskell (Hugs98)
J2SE 1.4 Class
J2SE 1.4 Fragment
J2SE 5.0 Class
J2SE 5.0 Fragment
J2SE 6.0 Class
J2SE 6.0 Fragment
Perl
Python
Ruby
 
Ruby Code Examples

If you haven't done so already, why not read the Zamplized Ruby User's Guide?

This page contains Ruby live code examples that we thought were interesting.

The following code examples were taken from Why's (Poignant) Guide to Ruby.

Reading a web page

This code example was taken from chapter 3, section 4.

require 'net/http'
Net::HTTP.start( 'www.ruby-lang.org', 80 ) do |http|
    print( http.get( '/en/LICENSE.txt' ).body )
end

Arrays of Hashes

This code example was taken from chapter 4, section 4.

kitty_toys = [
   {:shape => 'sock', :fabric => 'cashmere'},
   {:shape => 'mouse', :fabric => 'calico'},
   {:shape => 'eggroll', :fabric => 'chenille'}
]

kitty_toys.sort_by { |toy| toy[:shape] }.each do |toy|
   puts "Blixy has a #{ toy[:shape] } made of #{ toy[:fabric] }" 
end

Output

Blixy has a eggroll made of chenille
Blixy has a mouse made of calico
Blixy has a sock made of cashmere

Add New Code Samples Here

If you have code samples that don't fit into any of the topics above which you would like to contribute, please put them here.  We'll sort them out into their own sections as appropriate later.

0 Quality Tested Examples 0 Problems & Suggestions 0 Closed Issues
to add a new posting or reply to an existing posting.