Kleber S.
Kleber S.

Reputation: 8240

How to get constant name by filename

Given a filename, I would like to know if there is a ruby way to obtain the constant name for it.

e.g:

"lib/myproject/connect.rb" => MyProject::Connect

p.s: I know I can create a script for this.

EDIT: consider only the first one at the top.

Upvotes: 3

Views: 357

Answers (1)

spickermann
spickermann

Reputation: 106882

You may wanna take a look at the implementation of Inflector#camelize in ActiveSupport, see: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-camelize

Upvotes: 3

Related Questions