moduleParclassResultattr_reader:objdefinitializeobj@obj=objenddef>>other# Concatenation with another Resultifother.respond_to?:objreturnconcat(obj,other.obj)end# Concatenation with bottomreturnbottomifother==bottomreturnselfifother==top# Wild concatenation with any other objectreturnconcat(obj,other)enddefmaybeselfenddefasreplacement=nil,&blockunlessblock_given?returnResult.new(replacement)endreturnResult.new(block.call(@obj))enddefnewobjself.class.newobjenddefbottomself.class.bottomenddeftopself.class.topenddefbottom?falseenddefconcatobj1,obj2new(obj1+obj2)enddefto_strobj.to_strenddefto_sobj.to_senddefinspect"result(#{obj.inspect})"enddef<=>otherobj<=>otherendincludeComparabledefself.bottom@bottom||=Bottom.newenddefself.top@top||=Top.newendclassBottomdef>>otherselfenddefmaybePar.topenddefbottom?trueenddefasobj=nil,&blockselfendendclassTopdef>>otherotherenddefmaybeselfenddefbottom?falseenddefasobj=nil,&blockunlessblock_given?returnResult.new(obj)endreturnResult.new(block.call(self))endendendend