that seems overly complicated for ruby if a is a file.
c = []; a.lines{c << a.pos}
As far as $, you may know it from Regex as the new line indicator.