9

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?

1 Answer 1

12

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

Sign up to request clarification or add additional context in comments.

2 Comments

When I used this command in Rails I got as Result "Base:0x007fd84b37b948>"
Sorry this happened because I already had initialized an Object! Thanks again

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.