If I have a file model.rb
:
require 'foo.rb'
require 'foo/bar.rb'
class Model
def self.foo
Foo.new
end
def bar
Foo::Bar.to_s
end
Foo::Bar::Baz.class_does_not_exist
end
How could I parse this file to return valid class references? For instance, if Foo
and Foo::Bar
are defined elsewhere, but Foo::Bar::Baz
is not, then I would want something like:
parse_for_valid_class_references(File.open('model.rb', 'rb'))
# => [Foo, Foo::Bar]