Posted By

rkumar on 09/23/10


Tagged

ruby


Versions (?)

get word under cursor


 / Published in: Ruby
 

  1. # given a line and a cursor position returns the word
  2. # under the cursor. Takes only spaces into account, not punctuation
  3. # characters.
  4. def _get_word_under_cursor line, pos
  5. finish = line.index(" ", pos)
  6. start = line.rindex(" ",pos)
  7. finish = -1 if finish.nil?
  8. start = 0 if start.nil?
  9. return line[start..finish]
  10. end

Report this snippet  

You need to login to post a comment.