I shall try this one. I realize to work more on the subject. There are waysI don't think of. !

Thanks for the help.

Ronan

 


Envoy de mon smartphone BlackBerry 10 sur le rseau SFR.
 Message d'origine 
De: Hassan Schroeder
Envoy: jeudi 11 septembre 2014 20:36
: Ruby users
Rpondre : Ruby users
Objet: Re: Something messy

2014-09-11 9:53 GMT-07:00 <ron.lelay / gmail.com>:

> I always get lost when it comes to if statements.

They can be hard to follow when overused, and there are frequently
more readable approaches. Here's one example:

dep =["Ain","Aisne","Allier","Hautes-Alpes","Alpes-de-Haute-Provence","Alpes-Maritimes","Ardche","Ardennes","Arige","Aube","Aude","Aveyron",
"Bouches-du-Rhne","Calvados","Cantal","Charente","Charente-Maritime","Cher","Corrze","Corse-du-sud","Haute-corse","Cte-d'or",
"Ctes-d'armor","Creuse","Dordogne","Doubs","Drme","Eure","Eure-et-Loir","Finistre","Gard","Haute-Garonne","Gers","Gironde","Hrault",
"Ile-et-Vilaine","Indre","Indre-et-Loire","Isre","Jura","Landes","Loir-et-Cher","Loire","Haute-Loire","Loire-Atlantique","Loiret","Lot",
"Lot-et-Garonne","Lozre","Maine-et-Loire","Manche","Marne","Haute-Marne","Mayenne","Meurthe-et-Moselle","Meuse","Morbihan",
"Moselle","Nivre","Nord","Oise","Orne","Pas-de-Calais","Puy-de-Dme","Pyrnes-Atlantiques","Hautes-Pyrnes","Pyrnes-Orientales",
"Bas-Rhin","Haut-Rhin","Rhne","Haute-Sane","Sane-et-Loire","Sarthe","Savoie","Haute-Savoie","Paris","Seine-Maritime","Seine-et-Marne",
"Yvelines","Deux-Svres","Somme","Tarn","Tarn-et-Garonne","Var","Vaucluse","Vende","Vienne","Haute-Vienne","Vosges","Yonne",
"Territoire de Belfort","Essonne","Hauts-de-Seine","Seine-Saint-Denis","Val-de-Marne","Val-d'oise","Mayotte","Guadeloupe","Guyane","Martinique","Runion"]

puts "Num | Dpartement | Prfecture "
puts "------------------------------------------------"

def mark_as(index)
{'20' => '2A', '21' => '2B'}["#{index}"] || "%02d" % (index + 1)
end

dep.first(95).each_with_index do |depart, index|
puts sprintf "%s | %s", mark_as(index), depart
end

Just one possible approach, sans "ifs" :-)

Good luck,
-- 
Hassan Schroeder ------------------------ hassan.schroeder / gmail.com
http://about.me/hassanschroeder
twitter: @hassan