Le 29 septembre 2010 20:40, Adriano Ferreira a ˝─rit :

Hi.

> I'm about to introduce Ruby to a group of people that is not familiar to the 
> language, and the approach i'd like to take is simply by distilling out a few 
> sample codes. I've been collecting some from around the internet, but i'd 
> appreciate your suggestions as well.

In a presentation I made sometime ago, I used these at the beginning :

File.open("script.rb") do |fichier|
  fichier.each do |ligne|
    if ligne.downcase.include? "ruby"
      puts ligne 
    end
  end
end

File.open("script.rb") do |f|
  f.each { |l| puts l if l=~/ruby/i }
end

# The Lottery here is 7 out of 36 balls.
(1..36).sort_by { rand }.slice(0,7).join(', ')

fct1 = lambda { |v| v.split(/ /).
          collect { |z| z.capitalize }.join(' ') }
fct2 = lambda { |v| v.split(//).
          collect { |c| c.ord }.join(',') }
         
fct1.call("this is a nice string.")
fct2.call("this is another nice string.")

require "open-uri"
open('http://www.google.com/') { |f| puts f.read }

HTH,

Fred
-- 
She rules until the end of time
She gives and she takes
She rules until the end of time
She goes her own way                   (Within Temptation, Mother Earth)