Skip to content

Instantly share code, notes, and snippets.

@opsb
Created February 17, 2011 17:35
Show Gist options
  • Select an option

  • Save opsb/832204 to your computer and use it in GitHub Desktop.

Select an option

Save opsb/832204 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rspec'
def split(original)
original.split("/").inject([]) do |result, element|
result + [(result.last||[]) + [element]]
end.reverse.map{ |variation| variation.join("/") }
end
describe "#category" do
it "should split the categories out" do
split("bc6/energy/fuel/organic").should == ["bc6/energy/fuel/organic", "bc6/energy/fuel", "bc6/energy", "bc6"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment