How to get line number and file of your RoR code

    # parse caller to fetch filename, method & line of call
    def parse_caller(at)
      if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
        file = Regexp.last_match[1]
        line = Regexp.last_match[2].to_i
        method = Regexp.last_match[3]
        [file, line, method]
      end
    end
  file, line, method = parse_caller(caller(1).first)

Leave a Reply

Your email address will not be published. Required fields are marked *

70 − 60 =