One minute
values_at method to retrieve multiple non-sequential values ✌🏼
Do you know you can use values_at to retrieve multiple non-sequential values from array or hash?
Code snippet 📌
# For a given array it will return an array of the values associated with the index position.
❯ directions = [
'North',
'East',
'West',
'South'
]
❯ directions.values_at(0, 2)
❯ ["North", "West"]
# For a given hash it will return an array of the values associated with the given keys.
❯ directions = {
'N'=> 'North',
'E'=> 'East',
'W'=> 'West',
'S'=> 'South'
}
❯ directions.values_at('N', 'S')
❯ ["North", "South"]
Read other posts
comments powered by Disqus