Skip to content

Instantly share code, notes, and snippets.

@aantix
Last active September 24, 2022 16:10
Show Gist options
  • Save aantix/42480a662f2c777a24b43eb1694725dc to your computer and use it in GitHub Desktop.
Save aantix/42480a662f2c777a24b43eb1694725dc to your computer and use it in GitHub Desktop.
Getting all Rails application level classes and modules
Zeitwerk::Loader.eager_load_all && true
objs = []
ObjectSpace.each_object(Module){|ob| objs << [ob, ((Object.const_source_location(ob.to_s) rescue nil) || (Module.const_source_location(ob.to_s) rescue nil))]}
objs.reject!{|o| !(o&.last&.first =~ /#{Rails.root.to_s}/)}
objs = objs.collect{|c| c.flatten.first}
objs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment