Created
October 31, 2008 01:22
-
-
Save bbuckley/21195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:foo / :bar # => [:foo, :bar] | |
:foo / :bar / :fizz # => [:foo, :bar, :fizz] | |
:foo / :bar / :foo # => [:foo, :bar] | |
:foo / :bar / :fizz / :bizz # => [:foo, :bar, :fizz, :bizz] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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