[Vit-discuss] Top Ruby Projects algorithm?

John W. Long ng at johnwlong.com
Fri Aug 25 23:16:51 EDT 2006


James Edward Gray II wrote:
> That fills the box in every direction.  It's really hard to squeeze  
> something like a URL in that space.

Here are two that might fit the bill.

A better non-oo Hello World?

   # Hello World is trivial
   # in Ruby:
   puts "Hello World!"

   # It's also easy to work
   # with collections:
   [1, 3, 5].each do |i|
     puts i
   end

   # Everything in Ruby
   # is an object:
   puts -5.abs
   puts "abc".reverse


One using blocks:

   # Ruby can do amazing
   # things with blocks:
   5.times do
     puts "Ruby rocks!"
   end

   # A complex example:
   a = [1, 2, 3]
   total = a.inject(0) do
     |sum, i|
     sum + i
   end
   puts total #=> 6


Wow! I even used inject. I really like snippets that show several things 
and especially snippets that show a progression.

--
John Long
http://wiseheartdesign.com


More information about the vit-discuss mailing list