Skip to content

Instantly share code, notes, and snippets.

@VictorTpo
Last active December 13, 2016 23:50
Show Gist options
  • Save VictorTpo/763c9e7127d153329f3353e150a26358 to your computer and use it in GitHub Desktop.
Save VictorTpo/763c9e7127d153329f3353e150a26358 to your computer and use it in GitHub Desktop.

Before

$ item = Project::Speaker.find(5)
$ item.class.name      
> "Project::Speaker"
$ item.class.name.split('::').first
> "Project"
$ item.class.name.split('::').last
> "Speaker"

After

$ item = Project::Speaker.find(5)
$ item.class.name.deconstantize    
> "Project"
$ item.class.name.demodulize 
> "Speaker"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment