Closed thorstenhirsch closed 7 years ago
Hello @thorstenhirsch ,
of course this would be possible and i would like to improve the related regular expressions, but i'm not that familiar with ruby. Could you please provide a file including the code that needs to be covered by the symbols?
I would update the regexp (and maybe the current local test file) and come back to you afterwards.
Regards
Hi @mbuc82 , sure, let's just use this example I found in a Ruby tutorial:
#!/usr/bin/env ruby
class Foo
include SomeModule
def self.bar
puts 'class method'
end
def baz
puts 'instance method'
end
end
Foo.bar # => "class method"
Foo.baz # => NoMethodError: undefined method ‘baz’ for Foo:Class
Foo.new.baz # => instance method
Foo.new.bar # => NoMethodError: undefined method ‘bar’
I guess we can focus on the class and just skip the 4 lines at the bottom. So we have a class definition and 2 methods - a class method and an instance method:
You can use the keyword "class" for searching class definitions. Method definitions begin with "def". The distinction between class methods and instance methods is that all class methods begin with "self.".
I'm not sure what to do with namespaces. They look like this:
class Namespace::Foo
def self.bar
puts 'class method'
end
end
There's another way to define namespaces:
module Namespace
class Foo
def self.bar
puts 'class method'
end
end
end
It means the same as the other namespace example, it's just a different way to implement it. But I guess we don't need the namespace in the symbols list at all. So just skip everything before the (optional) "::" to fetch the class name in your regex like this:
/class (?:.*::)?(.+)/$1/
Hello @thorstenhirsch ,
thank you very much for that detailed explanation! I'll update the source and let you know, when it's finished.
Regards
Hello @thorstenhirsch ,
i've updated the regular expressions for Ruby, to differ between class methods and instance methods. I've also updated the existing ones to exclude the namespaces (in class definitions) and to fit the code better than before.
The improvements will be included within the upcoming release. Please let me know, if you face any further problems, until then i would close this issue.
Regards
I just upgraded to 2.4.0 and it seems to work great. Good job! Thank you!
Ruby's class methods are defined like this:
def self.bar; end
But symbols-list only shows "self". That's the part that is fixed in the definition of class methods. The real name is what comes after "self" and the dot. It would also be nice to have a visual distinction between class methods and instance methods. Maybe different colors or different icons like [c] and [i].