“abc”.respond_to?(:sub) returns true, but String.respond_to?(:sub) returns false.
The second returns false, because it asks whether objects of the class Class have a method sub, as String is an Object of Class. It is the same for methods()…
How do I do these things and especialy respond_to?() without creating an Object of that class.
If you are trying to confirm whether a method exists,
String.method_defined? :subwill work. If you are specifically interested in instance methods, use something like:Note that you have to use a string, not a symbol.