Sha256: 3a59d8377629027e82790e6462dcc5a71725e7f45f47a483212a7c196330c224
Contents?: true
Size: 1.04 KB
Versions: 4
Compression:
Stored size: 1.04 KB
Contents
require 'spec_helper' describe Option do let (:cat) { Cat.new("MOGGIE!") } let (:dog) { Dog.new("DOGGIE!") } context "== pattern matching ==" do subject do option.match do |m| m.some { |cat| cat.name } m.none { "no cat :-(" } end end context "a match can have one None branch, which matches only None" do let (:option) { None } it { should eq "no cat :-(" } end context "a match can have a catchall Some branch which matches any Some" do let (:option) { Some[cat] } it { should eq "MOGGIE!" } end it "can have multiple Some branches, each one matching a value" do Some[cat].match do |m| m.some(dog) { :canteloupe } m.some(cat) { :fishsticks } end.should eq :fishsticks end it "can take a lambda as a guard to match against" do Some[cat].match do |m| m.some ->(pet) { pet.name == "DOGGIE!" } { :fishsticks } m.some ->(pet) { pet.name == "MOGGIE!" } { :canteloupe } end.should eq :canteloupe end end end
Version data entries
4 entries across 4 versions & 1 rubygems