ctags icon indicating copy to clipboard operation
ctags copied to clipboard

Ruby: picked up partial name from dynamic method definition

Open mislav opened this issue 10 years ago • 3 comments

When dynamically defining methods from a string to be eval'd:

M.module_eval <<-RUBY
  def _run_#{type}() end
RUBY

a _run_ tag is generated, when it fact nothing should be generated since the string to be eval'd is interpolated at runtime, and as such, it's not safe to try to scan method definitions inside of it.

$ ctags --version
Universal Ctags Development, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Jul 21 2015, 12:41:18
  Addresses: <[email protected]>, https://github.com/universal-ctags/ctags
  Optional compiled features: +wildcards, +regex, +debug, +option-directory, +coproc

mislav avatar Jul 22 '15 23:07 mislav

What does `#' mean in ruby?

masatake avatar Jul 23 '15 05:07 masatake

I found a docment for `#'. http://docs.ruby-lang.org/ja/1.9.3/doc/symref.html#num

I found interesting comment.

https://github.com/universal-ctags/ctags/blob/master/parsers/ruby.c#L269-L287

masatake avatar Jul 23 '15 06:07 masatake

Yeah, #{} is string interpolation in Ruby. I guess that the parser scans def _run_ and immediately takes it as method definition even if the method’s name isn't yet complete. I think that it should instead ignore the whole definition.

mislav avatar Jul 24 '15 04:07 mislav