Sacar un Array del Indice

Hola buenas noches a todos,

tengo la siguiente duda, se tiene un modelo para el registro de
entrenamientos de atletismo y dentro del modelo esta definido un array
con
los tipos de entrenamiento,

TRAINING_BLOCKS = [
[ _(“Fartlek (for speed and pace)”), “fartlek” ],
[ _(“Hills (for strength)”), “hills” ],
[ _(“Intervals (for speed)”), “intervals” ],
[ _(“Tempo Runs (for speed and pace)”), “tempo_runs” ],
[ _(“The Long Run (for endurance)”), “long_run” ],
[ _(“Easy run (for recovery)”), “easy_run” ],
[ _(“Race (for competing)”), “race” ],
[ _(“Other…”), “other” ]
]

es decir, tengo un campo @training.block que podrá ser ‘fartlek’,
‘hills’,
‘intervals’ etc, el problema es cuando se busca un entrenamiento
@training.block y dice que es ‘farlek’, pero no se quiere mostrar
‘farlek’,
si no ‘Fartlek (for seed and pace)’ el problema es que no se como sacar
el
indice del array

Alguna idea

Gracias

Mauricio Dulcce

+57 300 325 0335
Trasn 9c No. 130c-21
Bogotá, Colombia

Privileged/Confidential Information may be contained in this message. If
you

are not the addressee indicated in this message or responsible for
delivery
of the message to such person), you may not copy or deliver this message
to
anyone. In such case, you should destroy this message and kindly notify
the
sender by reply email. Please advise immediately if you or your employer
do
not consent to Internet email for messages of this kind. Opinions,
conclusions and other information in this message that do not relate to
the
official business of my firm shall be understood as neither given nor
endorsed by it.

On Jan 4, 2008, at 10:13 PM, Mauricio D. wrote:

[ _(“Easy run (for recovery)”), “easy_run” ],
se como sacar el indice del array
No se si necesitas de verdad ese vector, pero para esto lo que
necesitarias es un hash. Si necesitas ambas estructuras lo suyo es
construir una a partir de la otra:

 # sin probar, escrito sobre la marcha
 TRAINING_BLOCKS_BY_KEY =

Hash[*TRAINING_BLOCKS.map(:&reverse).flatten]

Si no, construyes el hash directamente en lugar del array.

– fxn

O como dice Xavier N., creando directamente un Hash, o utilizando …

 class Array
   def to_h
     self.inject({}) { |hash, value| hash.update value.first =>

value.last }
end
end

Entonces seria …

TRAINING_BLOCKS.to_h

Francesc

On Jan 4, 2008, at 10:13 PM, Mauricio D. wrote:

[ _(“Tempo Runs (for speed and pace)”), “tempo_runs” ],
@training.block y dice que es ‘farlek’, pero no se quiere mostrar

message. If you
to the
official business of my firm shall be understood as neither given nor
endorsed by it.


Ror-es mailing list
[email protected]
http://lists.simplelogica.net/mailman/listinfo/ror-es


name. Francesc E. i Martí
voice. +34 678.681.603