Is there a way to find out all the methods of a class by a command?


#1

Hi All,

I am learning the Ruby API, and I cam across the Ruby in 20 minutes tutorial. https://www.ruby-lang.org/en/documentation/quickstart/. In the tutorial there is a class called Greeter. Using the command Greeter.instance_methods(false) you can see all the methods within the class Greeter. I tried this with the built in Ruby Sketchup classes but it didn’t work. Is there a way to find out all the methods of a class?

David


#2

Some_class.methods.sort
Some_class.private_methods.sort
Some_class.constants.sort

etc…


#3

Sketchup.instance_methods(false)returns an empty array, becauseSketchup is aModule,not aClass.

Modules only have instance methods if they are to be used as a “mix-in” library via the globalincludeorextendmethods.

Sketchup::Edge.instance_methods(false).sortreturns the following array:
[:all_connected, :common_face, :curve, :end, :explode_curve, :faces, :find_faces, :length, :line, :other_vertex, :reversed_in?, :smooth=, :smooth?, :soft=, :soft?, :split, :start, :used_by?, :vertices]

FYI, In older SketchUp versions, under Ruby 1.8.x, the members of the array are strings instead of symbols.

It actually takes a lot longer than 20 minutes to learn Ruby. :wink: (wink)


#4

Other helpful global methods (that get inherited by all classes):

local_variables()
class_variables()
global_variables()

#5

You can find all methods in the api manual:
http://www.sketchup.com/intl/en/developer/


#6

Sorry, no you cannot.

Only the methods for SketchUp API modules and classes are listed in the online API manual.

For standard Ruby modules and classes, you must consult the Ruby documentation.
Ruby Core Classes
Ruby Standard Library