Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def line_at_pos(pos, string)
- pos = string.length + pos if pos < 0
- pos = 0 if pos < 0
- l = (string.rindex(/[\r\n]/, pos) || -1) + 1
- r = (string.index(/[\r\n]/, pos) || string.length) - 1
- string[l..r]
- end
Add Comment
Please, Sign In to add comment