[Vit-discuss] Top Ruby Projects algorithm?
John W. Long
ng at johnwlong.com
Fri Aug 25 15:32:00 EDT 2006
Gavin Kistner wrote:
>> There are a few snippets than can appear in that box. They can
>> change about every five minutes, if memory serves (due to caching).
>
> Excellent. :)
We currently have the following:
Hello World 1:
# The Greeter class
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
# Create a new object
g = Greeter.new("world")
# Output "Hello World!"
g.salute
Hello World 2:
# The famous Hello World
# program is trivial in
# Ruby. You don't need:
#
# * a "main" method
# * newline escapes
# * semicolons
#
# Here's the code:
puts "Hello World!"
I Love Ruby:
# Output "I *love* Ruby"
say = "I love Ruby"
puts say
# Output "I *LOVE* RUBY"
say['love'] = "*love*"
puts say.upcase
# Output "I *love* Ruby"
# five times
5.times { puts say }
Suggestions?
--
John Long
http://wiseheartdesign.com
More information about the vit-discuss
mailing list