#!/usr/bin/env ruby # This code comes from http://ruby-it.org/pages/blocchi+in+ruby # Check the page for copyright notice and explanations [1,2,3].each do |i| p i end 1 2 3 [persona1,persona2,persona3].max #=> persona2 [persona1,persona2,persona3].max { |a,b| a.name <=> b.name } nuova= Collezione.new for elem in vecchia risultato=trasforma(elem) ... ... nuova.add(risultato) end nuova= vecchia.map{|elem| trasforma(elem)} >> '1, 2 e 3'.gsub /[1-3]/ do |match| ?> case match >> when '1' >> 'uno' >> when '2' >> 'due' >> when '3' >> 'tre' >> end >> end => "uno, due e tre" begin file= open('testo.txt') ..lavora con file... rescue SomeException .. ensure file.close end open('file.txt') do |f| ..lavora con f.. end