Created
March 14, 2013 01:40
-
-
Save JonRowe/5158141 to your computer and use it in GitHub Desktop.
Fetch all the classes in the Object namespace...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def blacklist | |
[ | |
:Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, :NIL, :Data, | |
:TrueClass, :TRUE, :FalseClass, :FALSE, :Encoding, :Comparable, :Method, | |
:String, :Symbol, :Exception, :SystemExit, :SignalException, :Interrupt, | |
:StandardError, :TypeError, :ArgumentError, :IndexError, :KeyError, :Dir, | |
:RangeError, :ScriptError, :SyntaxError, :LoadError, :NotImplementedError, | |
:NameError, :NoMethodError, :RuntimeError, :SecurityError, :NoMemoryError, | |
:EncodingError, :SystemCallError, :Errno, :ZeroDivisionError, :Enumerable, | |
:FloatDomainError, :Numeric, :Integer, :Fixnum, :Float, :Bignum, :Array, | |
:Hash, :ENV, :Struct, :RegexpError, :Regexp, :MatchData, :Marshal, :Range, | |
:IOError, :EOFError, :IO, :STDIN, :STDOUT, :STDERR, :ARGF, :FileTest, :File, | |
:Time, :Random, :Signal, :Process, :Proc, :LocalJumpError, :UnboundMethod, | |
:Binding, :Math, :GC, :ObjectSpace, :Enumerator, :StopIteration, :RubyVM, | |
:Thread, :TOPLEVEL_BINDING, :ThreadGroup, :Mutex, :ThreadError, :Fiber, | |
:FiberError, :Rational, :Complex, :RUBY_RELEASE_DATE, :RUBY_PLATFORM, :ARGV, | |
:RUBY_PATCHLEVEL, :RUBY_REVISION, :RUBY_DESCRIPTION, :RUBY_COPYRIGHT, :Gem, | |
:RUBY_ENGINE, :TracePoint, :RbConfig, :Config, :CROSS_COMPILING, :Date, :IRB, | |
:Exception2MessageMapper, :RubyToken, :RubyLex, :Readline, :SystemStackError | |
] + ENV.keys.map(&:to_sym) | |
end | |
def constants_for name | |
(name.constants - blacklist).map { |constant| name.const_get constant } | |
end | |
def classes_for constant | |
if constant.is_a? Class | |
[constant] | |
elsif constant.is_a? Module | |
constants_for(constant).inject([]) do |array,constant| | |
array << classes_for(constant) | |
array | |
end | |
else | |
[] | |
end | |
end | |
def constants | |
constants_for(Object) | |
end | |
def classes | |
constants.map { |const| classes_for const }.flatten | |
end | |
module A | |
class B | |
end | |
end | |
class C | |
end | |
puts "Consts => #{constants}" | |
puts "Classes => #{classes}" |
It also might be because I setup the blacklist based on 2.0.0 constants, just add the extra 1.9.2 ones into the black list...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems that one of my classes are causing an issue here, but this is more than enough to get me going anyway - thanks! :)
=> nil