M
M
Magic Code2020-11-16 13:20:32
ruby
Magic Code, 2020-11-16 13:20:32

How to get the value of all hash keys?

Guys, hello everyone!

I have a hash, I need to get the values ​​of all keys 'D n ', where n is numbers from 0 to 27 .
My code:

sheet.rows.each_with_index do |row, index|
  index.to_s
  puts row["D#{index}"] # => ничего
end

How to write code correctly? In addition to the Dn key , there are other keys.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2020-11-16
@Panda_Code

# h - данный хэш
h.each do |k, _|
  puts h[k] if k.match?(/^D\d{1,2}$/) && k[/[0-9]+/].to_i.between?(0, 27)
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question