Reputation: 6259
Lets say I have I class called
a = Person::User::Base
How can I get only the last subclass called Base
.
The way i know how to do this is:
a.to_s.split('::').last
=> "Base"
Is there a better way?
Upvotes: 9
Views: 1287
Reputation: 5041
If you use Rails (ActiveSupport):
a.to_s.demodulize
If you use POR (plain-ol-Ruby), yes, it's your way:
a.to_s.split('::').last
Upvotes: 12