Tuesday, 10 September 2013

Ruby check if constant is a class

Ruby check if constant is a class

I want to make a ruby gem which standardizes a serious of APIs.
The logic associated with connecting to each API needs to be abstracted
into .rb files. To load each of the API's logic, I'm looping through the
files of a folder:
# Require individual API logic
Dir[File.dirname(__FILE__) + "/standard/apis/*.rb"].each do |file|
require file
end
Each API is a constant of the StandardAPI, so I can to iterate some code
over each API:
StandardAPI.constants.each do |constant|
# Standardize this stuff
end
However, I have a VERSION constant too. It loops over my API logic classes
just fine, but when I gets to VERSION, I run into:
:VERSION is not a class/module (TypeError)
How can I loop over each of the APIs ignoring constants that aren't my
required classes?

No comments:

Post a Comment