I’m playing with a simple “breadcrumb” nav in Rails and I want to split my current path into a series of strings. Yes I know there are libraries for this, but I am interested in how you would pull the following task off in pure Ruby.
Let’s say you have a url path string like this:
/users/admins/1/edit
And you want to return an array of strings like this:
["/users","/users/admins","users/admins/1","users/admins/1/edit"]
How would you go about doing so? I’ve tried to use the each_index functions to add each subsequent portion together and shove it in a new array, but I can never get a true recursive addition of the strings.
Any ideas?
Second variant inspired by pguardiario