I apply .instance_methods(false) on class String, class Array etc…
I build up an Array for completable methods, and feed this to the
ruby Readline module. This already works fine as is, completion works.
But there is one problem:
Right now I hardcode this. So I have an Array that I have to maintain
on my own and I perhaps missed some core components (I am sloppy and
lazy)
So here is my question:
Is there a way to programmatically obtain all corelib constants?
(In particular, I am interested in the major classes/modules that
are part of corelib such as class Hash and so forth, not any sublevel
constants.)
To create an array with separate objects a block can be passed instead.
This method is … In case of Array’s each, all elements in the Array
instance are yielded to the supplied block in sequence.
Is there a way to programmatically obtain all corelib constants?
(In particular, I am interested in the major classes/modules that
are part of corelib such as class Hash and so forth, not any sublevel
constants.)
So that I get an Array such as:
[ String, Float, Object, Hash, Array etc…]
get all known class :
def getc()
h={}
ObjectSpace.each_object {|a| h[a.name]=a if a && Class === a }
h
end
get all constants of all class:
def getconst()
h={}
ObjectSpace.each_object do |a|
h[a.name]=a.constants if a && Class === a && a.constants.size>0
end
h
end
def get_data_const()
h={}
ObjectSpace.each_object do |a|
if a && Class === a && a.constants.size>0
l=a.constants.select {|const|
v=a.const_get(const);
v.class!=Class && v.class!=Module
}
h[a.name]= l if l.size>0
end
end
h
end