DATA.each_line - why array header_names does not print "A", "B", "C"?

solved here: https://stackoverflow.com/questions/55519210/data-each-line-not-returning-header-names
Why array header_names does not print “A”, “B”, “C”?

header_names =

this works OK

str = “|X|Y|Z|”
a = str.split(/|/)
p a

DATA.each_line { |e|
if e =~ /|/
header_names = e.split(/|/)
return header_names
end
}
p header_names # why it does not print “A”, “B”, “C”

END
blah blah
|A|B|C|
|1|1|1|
|2|2|2|

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs