Skip to content

Instantly share code, notes, and snippets.

@bbuckley
Created October 31, 2008 01:22
Show Gist options
  • Save bbuckley/21195 to your computer and use it in GitHub Desktop.
Save bbuckley/21195 to your computer and use it in GitHub Desktop.
:foo / :bar # => [:foo, :bar]
:foo / :bar / :fizz # => [:foo, :bar, :fizz]
:foo / :bar / :foo # => [:foo, :bar]
:foo / :bar / :fizz / :bizz # => [:foo, :bar, :fizz, :bizz]
class Symbol
class SymbolSet < Array
def /(sym)
SymbolSet.new([self, sym].flatten.uniq)
end
end
def /(sym)
SymbolSet.new([self, sym])
end
end
if __FILE__ == $0
%w(rubygems spec).each { |lib| require lib }
describe Symbol, "/" do
it "returns array" do
result = :foo / :bar
result.should == [:foo, :bar]
end
describe "SymbolSet" do
it "allows chaining" do
result = :foo / :bar / :fizz / :bizz
result.should == [:foo, :bar, :fizz, :bizz]
end
it "is unique" do
result = :foo / :bar / :foo
result.should == [:foo, :bar]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment