carats 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +2 -0
- data/LICENSE +5 -0
- data/README +67 -0
- data/Reapfile +72 -0
- data/ToDo +24 -0
- data/bench/b_harray.rb +49 -0
- data/bench/b_range.rb +64 -0
- data/demo/ansicolor/cdiff.rb +20 -0
- data/demo/ansicolor/example.rb +82 -0
- data/demo/io-reactor/chatserver.rb +347 -0
- data/doc/classes/Array.html +172 -0
- data/doc/classes/BBCode.html +638 -0
- data/doc/classes/BinaryReader.html +675 -0
- data/doc/classes/Binding.html +223 -0
- data/doc/classes/ByteOrder.html +284 -0
- data/doc/classes/Class.html +189 -0
- data/doc/classes/Constant.html +785 -0
- data/doc/classes/Constant/CGS.html +609 -0
- data/doc/classes/Continuation.html +113 -0
- data/doc/classes/Coroutine.html +387 -0
- data/doc/classes/CountingSemaphore.html +337 -0
- data/doc/classes/CrossCase.html +561 -0
- data/doc/classes/DynamicMixin.html +185 -0
- data/doc/classes/EnumerableWithArgs.html +550 -0
- data/doc/classes/Expect.html +428 -0
- data/doc/classes/Expect/DefaultChain.html +113 -0
- data/doc/classes/Expect/SeparatedPattern.html +223 -0
- data/doc/classes/Expect/Timeout.html +167 -0
- data/doc/classes/Expect/UnmatchedMessage.html +160 -0
- data/doc/classes/FileList.html +833 -0
- data/doc/classes/FloatString.html +534 -0
- data/doc/classes/Functor.html +211 -0
- data/doc/classes/HArray.html +1872 -0
- data/doc/classes/HTML.html +328 -0
- data/doc/classes/Heap.html +683 -0
- data/doc/classes/Heap/EmptyHeapException.html +111 -0
- data/doc/classes/Heap/Max.html +176 -0
- data/doc/classes/Heap/Min.html +176 -0
- data/doc/classes/IO.html +108 -0
- data/doc/classes/IO/Reactor.html +790 -0
- data/doc/classes/IO/Redirect.html +289 -0
- data/doc/classes/Infinity.html +320 -0
- data/doc/classes/Interval.html +1014 -0
- data/doc/classes/InvalidNackError.html +161 -0
- data/doc/classes/Kernel.html +204 -0
- data/doc/classes/Lisp.html +1132 -0
- data/doc/classes/Lisp/DottedPair.html +379 -0
- data/doc/classes/Lisp/Format.html +178 -0
- data/doc/classes/Lisp/Format/ArgumentError.html +126 -0
- data/doc/classes/Lisp/Format/Directives.html +155 -0
- data/doc/classes/Lisp/Format/Directives/ArgJump.html +178 -0
- data/doc/classes/Lisp/Format/Directives/Ascii.html +119 -0
- data/doc/classes/Lisp/Format/Directives/BeginCaseConversion.html +185 -0
- data/doc/classes/Lisp/Format/Directives/BeginConditional.html +307 -0
- data/doc/classes/Lisp/Format/Directives/BeginIteration.html +338 -0
- data/doc/classes/Lisp/Format/Directives/Binary.html +157 -0
- data/doc/classes/Lisp/Format/Directives/Character.html +228 -0
- data/doc/classes/Lisp/Format/Directives/CharacterDirective.html +203 -0
- data/doc/classes/Lisp/Format/Directives/ClauseSeparator.html +166 -0
- data/doc/classes/Lisp/Format/Directives/Decimal.html +119 -0
- data/doc/classes/Lisp/Format/Directives/Directive.html +397 -0
- data/doc/classes/Lisp/Format/Directives/DollarFP.html +205 -0
- data/doc/classes/Lisp/Format/Directives/EndCaseConversion.html +174 -0
- data/doc/classes/Lisp/Format/Directives/EndConditional.html +159 -0
- data/doc/classes/Lisp/Format/Directives/EndIteration.html +163 -0
- data/doc/classes/Lisp/Format/Directives/ExpFP.html +252 -0
- data/doc/classes/Lisp/Format/Directives/FFFP.html +224 -0
- data/doc/classes/Lisp/Format/Directives/Factory.html +180 -0
- data/doc/classes/Lisp/Format/Directives/FreshLine.html +175 -0
- data/doc/classes/Lisp/Format/Directives/GeneralFP.html +265 -0
- data/doc/classes/Lisp/Format/Directives/Hexadecimal.html +157 -0
- data/doc/classes/Lisp/Format/Directives/Indirection.html +183 -0
- data/doc/classes/Lisp/Format/Directives/Literal.html +187 -0
- data/doc/classes/Lisp/Format/Directives/NewLine.html +158 -0
- data/doc/classes/Lisp/Format/Directives/NewPage.html +158 -0
- data/doc/classes/Lisp/Format/Directives/Number.html +243 -0
- data/doc/classes/Lisp/Format/Directives/Octal.html +157 -0
- data/doc/classes/Lisp/Format/Directives/Plural.html +177 -0
- data/doc/classes/Lisp/Format/Directives/Print.html +237 -0
- data/doc/classes/Lisp/Format/Directives/Radix.html +432 -0
- data/doc/classes/Lisp/Format/Directives/SExpression.html +157 -0
- data/doc/classes/Lisp/Format/Directives/SkipWhitespace.html +165 -0
- data/doc/classes/Lisp/Format/Directives/Tabulate.html +198 -0
- data/doc/classes/Lisp/Format/Directives/Tilde.html +158 -0
- data/doc/classes/Lisp/Format/Directives/UnknownDirectiveError.html +117 -0
- data/doc/classes/Lisp/Format/Formatter.html +193 -0
- data/doc/classes/Lisp/Format/IncompleteParameterError.html +119 -0
- data/doc/classes/Lisp/Format/IndexError.html +126 -0
- data/doc/classes/Lisp/Format/Lexer.html +479 -0
- data/doc/classes/Lisp/Format/MalformedError.html +119 -0
- data/doc/classes/Lisp/Format/MissingParameterError.html +119 -0
- data/doc/classes/Lisp/Format/ModifierError.html +119 -0
- data/doc/classes/Lisp/Format/Output.html +239 -0
- data/doc/classes/Lisp/Format/ParameterError.html +126 -0
- data/doc/classes/Lisp/Format/Parameters.html +123 -0
- data/doc/classes/Lisp/Format/Parameters/Argument.html +172 -0
- data/doc/classes/Lisp/Format/Parameters/ArgumentCount.html +159 -0
- data/doc/classes/Lisp/Format/Parameters/Character.html +119 -0
- data/doc/classes/Lisp/Format/Parameters/Default.html +120 -0
- data/doc/classes/Lisp/Format/Parameters/Integer.html +119 -0
- data/doc/classes/Lisp/Format/Parameters/Parameter.html +206 -0
- data/doc/classes/Lisp/Format/Parser.html +212 -0
- data/doc/classes/Lisp/Format/Positioned.html +166 -0
- data/doc/classes/Lisp/Format/State.html +455 -0
- data/doc/classes/Lisp/Format/SyntaxError.html +126 -0
- data/doc/classes/Method.html +274 -0
- data/doc/classes/Method/DuckHunter.html +281 -0
- data/doc/classes/Module.html +709 -0
- data/doc/classes/Multiton.html +284 -0
- data/doc/classes/Multiton/New.html +164 -0
- data/doc/classes/Multiton/Semi.html +155 -0
- data/doc/classes/NackClass.html +322 -0
- data/doc/classes/NilClass.html +231 -0
- data/doc/classes/NilComparable.html +179 -0
- data/doc/classes/NotCopyable.html +273 -0
- data/doc/classes/Object.html +261 -0
- data/doc/classes/OpenStructable.html +346 -0
- data/doc/classes/OrderedHash.html +939 -0
- data/doc/classes/Parser.html +515 -0
- data/doc/classes/Parser/Main.html +178 -0
- data/doc/classes/Parser/Marker.html +475 -0
- data/doc/classes/Parser/Registry.html +354 -0
- data/doc/classes/Parser/Token.html +399 -0
- data/doc/classes/Parser/UnitToken.html +222 -0
- data/doc/classes/Ref.html +230 -0
- data/doc/classes/SimpleStringIO.html +183 -0
- data/doc/classes/StaticHash.html +202 -0
- data/doc/classes/String.html +172 -0
- data/doc/classes/Struct.html +181 -0
- data/doc/classes/SuperStruct.html +382 -0
- data/doc/classes/Term.html +156 -0
- data/doc/classes/Term/ANSIColor.html +185 -0
- data/doc/classes/Text.html +138 -0
- data/doc/classes/Text/Soundex.html +222 -0
- data/doc/classes/TextTagIterator.html +911 -0
- data/doc/classes/Time.html +119 -0
- data/doc/classes/Time/Limit.html +303 -0
- data/doc/classes/Time/Limit/Dummy.html +181 -0
- data/doc/classes/Timer.html +351 -0
- data/doc/classes/TracePoint.html +532 -0
- data/doc/classes/Tuple.html +178 -0
- data/doc/classes/Uninheritable.html +213 -0
- data/doc/classes/Version.html +783 -0
- data/doc/created.rid +1 -0
- data/doc/files/LICENSE.html +113 -0
- data/doc/files/README.html +201 -0
- data/doc/files/lib/carat/1st_rb.html +107 -0
- data/doc/files/lib/carat/ansicolor_rb.html +146 -0
- data/doc/files/lib/carat/attr_rb.html +101 -0
- data/doc/files/lib/carat/bbcode_rb.html +152 -0
- data/doc/files/lib/carat/binaryreader_rb.html +114 -0
- data/doc/files/lib/carat/binding-of-caller_rb.html +108 -0
- data/doc/files/lib/carat/byteorder_rb.html +107 -0
- data/doc/files/lib/carat/constant_rb.html +167 -0
- data/doc/files/lib/carat/coroutine_rb.html +156 -0
- data/doc/files/lib/carat/crosscase_rb.html +224 -0
- data/doc/files/lib/carat/duckhunter_rb.html +165 -0
- data/doc/files/lib/carat/dynamic-mixin_rb.html +101 -0
- data/doc/files/lib/carat/enumerable-args_rb.html +140 -0
- data/doc/files/lib/carat/expect_rb.html +137 -0
- data/doc/files/lib/carat/filelist_rb.html +130 -0
- data/doc/files/lib/carat/floatstring_rb.html +126 -0
- data/doc/files/lib/carat/functor_rb.html +140 -0
- data/doc/files/lib/carat/harray_rb.html +128 -0
- data/doc/files/lib/carat/heap_rb.html +154 -0
- data/doc/files/lib/carat/html-helpers_rb.html +116 -0
- data/doc/files/lib/carat/infinity_rb.html +142 -0
- data/doc/files/lib/carat/init_rb.html +127 -0
- data/doc/files/lib/carat/interval_rb.html +162 -0
- data/doc/files/lib/carat/io-reactor_rb.html +211 -0
- data/doc/files/lib/carat/io-redirect_rb.html +132 -0
- data/doc/files/lib/carat/lisp-format_rb.html +187 -0
- data/doc/files/lib/carat/lisp_rb.html +152 -0
- data/doc/files/lib/carat/macro_rb.html +129 -0
- data/doc/files/lib/carat/multiton_rb.html +178 -0
- data/doc/files/lib/carat/nack_rb.html +193 -0
- data/doc/files/lib/carat/nil-comparable_rb.html +126 -0
- data/doc/files/lib/carat/nil-missing_rb.html +101 -0
- data/doc/files/lib/carat/notcopyable_rb.html +166 -0
- data/doc/files/lib/carat/orderedhash_rb.html +107 -0
- data/doc/files/lib/carat/ostructable_rb.html +157 -0
- data/doc/files/lib/carat/parser-old_rb.html +239 -0
- data/doc/files/lib/carat/parser_rb.html +244 -0
- data/doc/files/lib/carat/ref_rb.html +107 -0
- data/doc/files/lib/carat/semaphore_rb.html +132 -0
- data/doc/files/lib/carat/snapshot_rb.html +152 -0
- data/doc/files/lib/carat/soundex_rb.html +128 -0
- data/doc/files/lib/carat/sstruct_rb.html +142 -0
- data/doc/files/lib/carat/statichash_rb.html +150 -0
- data/doc/files/lib/carat/tagiter_rb.html +236 -0
- data/doc/files/lib/carat/timelimit_rb.html +136 -0
- data/doc/files/lib/carat/timer_rb.html +153 -0
- data/doc/files/lib/carat/tracepoint_rb.html +160 -0
- data/doc/files/lib/carat/tuple_rb.html +123 -0
- data/doc/files/lib/carat/uninheritable_rb.html +101 -0
- data/doc/files/lib/carat/version_rb.html +141 -0
- data/doc/fr_class_index.html +159 -0
- data/doc/fr_file_index.html +78 -0
- data/doc/fr_method_index.html +663 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/carat-dev/README +11 -0
- data/lib/carat-dev/access-blocks/access_blocks.rb +42 -0
- data/lib/carat-dev/association/association.rb +70 -0
- data/lib/carat-dev/blankslate/blankslate.rb +51 -0
- data/lib/carat-dev/breakpoint.rb +518 -0
- data/lib/carat-dev/class-constructor/constructor_methods.rb +78 -0
- data/lib/carat-dev/class-constructor/tc_constructor.rb +35 -0
- data/lib/carat-dev/closecall/closecall-test.rb +39 -0
- data/lib/carat-dev/closecall/closecall.rb +101 -0
- data/lib/carat-dev/commandrunner/commandrunner.rb +100 -0
- data/lib/carat-dev/conditional/conditionals.rb +106 -0
- data/lib/carat-dev/daemon/daemon.rb +70 -0
- data/lib/carat-dev/detach/detach.rb +363 -0
- data/lib/carat-dev/detach/tc_detach.rb +57 -0
- data/lib/carat-dev/import-module/import-module-0.81.tar.gz +0 -0
- data/lib/carat-dev/import-module/import-module-0.81/LICENSE +1 -0
- data/lib/carat-dev/import-module/import-module-0.81/Makefile +11 -0
- data/lib/carat-dev/import-module/import-module-0.81/README +4 -0
- data/lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-hash.rb +49 -0
- data/lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-pip.rb +71 -0
- data/lib/carat-dev/import-module/import-module-0.81/dev-lib/import-module-unbound-method.rb +36 -0
- data/lib/carat-dev/import-module/import-module-0.81/doc/README-ja.html +293 -0
- data/lib/carat-dev/import-module/import-module-0.81/doc/README-ja.rd +306 -0
- data/lib/carat-dev/import-module/import-module-0.81/doc/README.html +290 -0
- data/lib/carat-dev/import-module/import-module-0.81/doc/README.rd +303 -0
- data/lib/carat-dev/import-module/import-module-0.81/doc/style.css +85 -0
- data/lib/carat-dev/import-module/import-module-0.81/install.rb +99 -0
- data/lib/carat-dev/import-module/import-module-0.81/lib/import-module-single-thread.rb +84 -0
- data/lib/carat-dev/import-module/import-module-0.81/lib/import-module.rb +493 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/Makefile +2 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test +91 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test-import-module.rb +936 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test-import_scope.rb +33 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test-scope_import.rb +33 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test-time.rb +184 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/test.sh +91 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/time.rb +135 -0
- data/lib/carat-dev/import-module/import-module-0.81/test/times-do.sh +10 -0
- data/lib/carat-dev/interface_work/SCRAP/i-contracts.rb +37 -0
- data/lib/carat-dev/interface_work/SCRAP/interface.rb +105 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0.zip +0 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/CHANGES +3 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/MANIFEST +15 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/README +32 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/doc/interface.rd +73 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/doc/interface.txt +94 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/install.rb +16 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/lib/interface.rb +50 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/test/tc_interface.rb +51 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/test/test.rb +29 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/test/test_instance.rb +24 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/test/test_sub.rb +29 -0
- data/lib/carat-dev/interface_work/SCRAP/j-interface/interface-0.1.0/test/test_unrequire.rb +28 -0
- data/lib/carat-dev/interface_work/contracts/contract.zip +0 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.html +376 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000001.html +23 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000002.html +18 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000003.html +19 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000004.html +29 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000005.html +18 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract.src/M000006.html +18 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract/ContractError.html +142 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract/ContractException.html +153 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Contract/ContractMismatch.html +125 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Module.html +157 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/classes/Module.src/M000007.html +112 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/created.rid +1 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/files/lib/contract/assertions_rb.html +109 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/files/lib/contract/exception_rb.html +108 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/files/lib/contract/integration_rb.html +108 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/files/lib/contract/overrides_rb.html +109 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/files/lib/contract_rb.html +114 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/fr_class_index.html +31 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/fr_file_index.html +31 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/fr_method_index.html +33 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/index.html +24 -0
- data/lib/carat-dev/interface_work/contracts/contract/doc/rdoc-style.css +208 -0
- data/lib/carat-dev/interface_work/contracts/contract/lib/contract.rb +88 -0
- data/lib/carat-dev/interface_work/contracts/contract/lib/contract/assertions.rb +37 -0
- data/lib/carat-dev/interface_work/contracts/contract/lib/contract/exception.rb +92 -0
- data/lib/carat-dev/interface_work/contracts/contract/lib/contract/integration.rb +132 -0
- data/lib/carat-dev/interface_work/contracts/contract/lib/contract/overrides.rb +32 -0
- data/lib/carat-dev/interface_work/must.rb +37 -0
- data/lib/carat-dev/interface_work/type.rb +232 -0
- data/lib/carat-dev/main/tc_toplevel.rb +23 -0
- data/lib/carat-dev/main/toplevel.rb +33 -0
- data/lib/carat-dev/main/toplevel_test.rb +24 -0
- data/lib/carat-dev/misc/1.rb +40 -0
- data/lib/carat-dev/misc/misc.rb +44 -0
- data/lib/carat-dev/misc/sys.rb +186 -0
- data/lib/carat-dev/misc/temp.rb +1 -0
- data/lib/carat-dev/misc/utils.rb +518 -0
- data/lib/carat-dev/predicate/predicate.rb +109 -0
- data/lib/carat-dev/predicate/predicate_test.rb +67 -0
- data/lib/carat-dev/premshree.rb +40 -0
- data/lib/carat-dev/priority-queue/pqueue.rb +183 -0
- data/lib/carat-dev/priority-queue/priorityqueue.rb +84 -0
- data/lib/carat-dev/quaternion/quaternion.rb +529 -0
- data/lib/carat-dev/range.rb +259 -0
- data/lib/carat-dev/system/rubyinfo.rb +75 -0
- data/lib/carat-dev/system/system.rb +105 -0
- data/lib/carat-dev/tc_range.rb +118 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.html +291 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000001.html +26 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000002.html +19 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000003.html +18 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000004.html +18 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000005.html +21 -0
- data/lib/carat-dev/timer/timer-doc/classes/Timer.src/M000006.html +23 -0
- data/lib/carat-dev/timer/timer-doc/created.rid +1 -0
- data/lib/carat-dev/timer/timer-doc/files/timer_rb.html +144 -0
- data/lib/carat-dev/timer/timer-doc/fr_class_index.html +27 -0
- data/lib/carat-dev/timer/timer-doc/fr_file_index.html +27 -0
- data/lib/carat-dev/timer/timer-doc/fr_method_index.html +32 -0
- data/lib/carat-dev/timer/timer-doc/index.html +24 -0
- data/lib/carat-dev/timer/timer-doc/rdoc-style.css +208 -0
- data/lib/carat-dev/timer/timer.rb +160 -0
- data/lib/carat-dev/vars/vars.rb +62 -0
- data/lib/carat/1st.rb +58 -0
- data/lib/carat/ansicolor.rb +122 -0
- data/lib/carat/attr.rb +342 -0
- data/lib/carat/bbcode.rb +352 -0
- data/lib/carat/binaryreader.rb +170 -0
- data/lib/carat/binding-of-caller.rb +83 -0
- data/lib/carat/byteorder.rb +34 -0
- data/lib/carat/constant.rb +287 -0
- data/lib/carat/coroutine.rb +102 -0
- data/lib/carat/crosscase.rb +309 -0
- data/lib/carat/duckhunter.rb +158 -0
- data/lib/carat/dynamic-mixin.rb +71 -0
- data/lib/carat/enumerable-args.rb +125 -0
- data/lib/carat/expect.rb +192 -0
- data/lib/carat/filelist.rb +277 -0
- data/lib/carat/floatstring.rb +153 -0
- data/lib/carat/functor.rb +41 -0
- data/lib/carat/harray.rb +507 -0
- data/lib/carat/heap.rb +193 -0
- data/lib/carat/html-helpers.rb +82 -0
- data/lib/carat/infinity.rb +61 -0
- data/lib/carat/init.rb +33 -0
- data/lib/carat/interval.rb +248 -0
- data/lib/carat/io-reactor.rb +657 -0
- data/lib/carat/io-redirect.rb +99 -0
- data/lib/carat/lisp-format.rb +1832 -0
- data/lib/carat/lisp.rb +336 -0
- data/lib/carat/macro.rb +68 -0
- data/lib/carat/multiton.rb +153 -0
- data/lib/carat/nack.rb +115 -0
- data/lib/carat/nil-comparable.rb +67 -0
- data/lib/carat/nil-missing.rb +12 -0
- data/lib/carat/notcopyable.rb +68 -0
- data/lib/carat/orderedhash.rb +249 -0
- data/lib/carat/ostructable.rb +138 -0
- data/lib/carat/parser-old.rb +350 -0
- data/lib/carat/parser.rb +393 -0
- data/lib/carat/ref.rb +31 -0
- data/lib/carat/semaphore.rb +69 -0
- data/lib/carat/snapshot.rb +94 -0
- data/lib/carat/soundex.rb +104 -0
- data/lib/carat/sstruct.rb +223 -0
- data/lib/carat/statichash.rb +49 -0
- data/lib/carat/tagiter.rb +345 -0
- data/lib/carat/timelimit.rb +114 -0
- data/lib/carat/timer.rb +99 -0
- data/lib/carat/tracepoint.rb +154 -0
- data/lib/carat/tuple.rb +31 -0
- data/lib/carat/uninheritable.rb +68 -0
- data/lib/carat/version.rb +147 -0
- data/pub/doc/sstruct.txt +204 -0
- data/pub/doc/tagiter.html +145 -0
- data/setup.rb +1361 -0
- data/test/fixtures/filelist/testfile.txt +1 -0
- data/test/fixtures/filelist/testfile2.txt +1 -0
- data/test/tc_1st.rb +16 -0
- data/test/tc_ansicolor.rb +23 -0
- data/test/tc_attr.rb +46 -0
- data/test/tc_bbcode.rb +20 -0
- data/test/tc_binaryreader.rb +14 -0
- data/test/tc_binding_of_caller.rb +2 -0
- data/test/tc_byteorder.rb +41 -0
- data/test/tc_constant.rb +12 -0
- data/test/tc_coroutine.rb +50 -0
- data/test/tc_crosscase.rb +33 -0
- data/test/tc_duckhunter.rb +37 -0
- data/test/tc_dynamic-mixin.rb +66 -0
- data/test/tc_enumerable-args.rb +66 -0
- data/test/tc_expect.rb +83 -0
- data/test/tc_filelist.rb +17 -0
- data/test/tc_floatstring.rb +22 -0
- data/test/tc_functor.rb +18 -0
- data/test/tc_harray.rb +280 -0
- data/test/tc_heap.rb +6 -0
- data/test/tc_infinity.rb +23 -0
- data/test/tc_init.rb +29 -0
- data/test/tc_interval.rb +153 -0
- data/test/tc_io-reactor.rb +5 -0
- data/test/tc_io-redirect.rb +5 -0
- data/test/tc_lisp-format.rb +24 -0
- data/test/tc_lisp.rb +32 -0
- data/test/tc_macro.rb +48 -0
- data/test/tc_multiton.rb +188 -0
- data/test/tc_nack.rb +31 -0
- data/test/tc_nil-as-emptiness.rb +19 -0
- data/test/tc_nil-comparable.rb +29 -0
- data/test/tc_nil-missing.rb +0 -0
- data/test/tc_notcopyable.rb +64 -0
- data/test/tc_orderedhash.rb +36 -0
- data/test/tc_ostructable.rb +31 -0
- data/test/tc_semaphore.rb +5 -0
- data/test/tc_snapshot.rb +20 -0
- data/test/tc_soundex.rb +19 -0
- data/test/tc_sstruct.rb +313 -0
- data/test/tc_statichash.rb +24 -0
- data/test/tc_tagiter.rb +80 -0
- data/test/tc_timelimit.rb +47 -0
- data/test/tc_timer.rb +35 -0
- data/test/tc_tracepoint.rb +10 -0
- data/test/tc_tuple.rb +25 -0
- data/test/tc_uninheritable.rb +33 -0
- data/test/tc_version.rb +90 -0
- metadata +531 -0
data/lib/carat/heap.rb
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= Heap
|
4
|
+
|
5
|
+
A Simple Heap structure and Sort
|
6
|
+
|
7
|
+
== Extending Heap
|
8
|
+
|
9
|
+
To extend the heap, implement a cmp(i,j) method which compares array
|
10
|
+
elements i and j and returns true iff i is larger than j, where larger or
|
11
|
+
is the required heap sorting. See Heap::Min and Heap::Max for examples.
|
12
|
+
|
13
|
+
== Note
|
14
|
+
|
15
|
+
The +parent+,+left+ and +right+ methods do not check the supplied parameter,
|
16
|
+
but their result is _only_ valid if the supplied with an integer >=0
|
17
|
+
for +left+ and +right+ and >0 for +parent+.
|
18
|
+
|
19
|
+
== Reference
|
20
|
+
|
21
|
+
<quote>
|
22
|
+
Cormen1990: Chapter 7 (Heapsort) of 'An introduction to algorithms', by
|
23
|
+
Cormen, T.H; Leiserson, C.E.; Rivest, R.L; MIT Press, Cambridge, 1990
|
24
|
+
ISBN 0-262-53091-0
|
25
|
+
</quote>
|
26
|
+
|
27
|
+
== Author
|
28
|
+
|
29
|
+
* Renald Buter (buter at cwts nl)
|
30
|
+
|
31
|
+
== Thanks
|
32
|
+
|
33
|
+
Special thanks to Nenad Ocelic for many suggestions.
|
34
|
+
|
35
|
+
== Legal
|
36
|
+
|
37
|
+
Copyright (c) 2002,2004 Renald Buter (Ruby Version)
|
38
|
+
[See Cormen1990 for original]
|
39
|
+
|
40
|
+
Ruby License...
|
41
|
+
|
42
|
+
== History
|
43
|
+
|
44
|
+
$Id: heap.rb,v 1.0 2004/11/30 transami Exp $
|
45
|
+
|
46
|
+
=end
|
47
|
+
|
48
|
+
class Heap
|
49
|
+
|
50
|
+
class EmptyHeapException < Exception; end
|
51
|
+
|
52
|
+
# We are an abstract class
|
53
|
+
private_class_method :new
|
54
|
+
def self.inherited(sub) sub.class_eval("public_class_method :new") end
|
55
|
+
|
56
|
+
# Keeps an heap sorted with the largest element on top
|
57
|
+
class Max < Heap
|
58
|
+
|
59
|
+
def initialize(array=[]) super(array) end
|
60
|
+
|
61
|
+
def cmp(a,b) a > b end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# Keeps an heap sorted with the smallest element on top
|
66
|
+
class Min < Heap
|
67
|
+
|
68
|
+
def initialize(array=[]) super(array) end
|
69
|
+
|
70
|
+
def cmp(a,b) a < b end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
# Initialise the heap. If supplied an array, build the heap with the values
|
75
|
+
# of the array. The array can be unsorted. Note: this method can only be
|
76
|
+
# called by superclasses
|
77
|
+
def initialize(array)
|
78
|
+
@array, @heap_size = array, array.length
|
79
|
+
(@heap_size/2 - 1).downto(0) { |i| heapify(i) }
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get the heap size
|
83
|
+
def size
|
84
|
+
@heap_size
|
85
|
+
end
|
86
|
+
|
87
|
+
# Pretty print
|
88
|
+
def to_s
|
89
|
+
"<#{self.class}: size=#@heap_size, top=#{self.top}>"
|
90
|
+
end
|
91
|
+
|
92
|
+
# Heap-sort a clone of the internal array. This will not touch the
|
93
|
+
# internal array. Returns the array sorted *reversely* on the heap
|
94
|
+
# condition!
|
95
|
+
def sort
|
96
|
+
old_ary = @array.dup
|
97
|
+
old_heap = @heap_size
|
98
|
+
new_ary = sort_internal
|
99
|
+
@array = old_ary
|
100
|
+
@heap_size = old_heap
|
101
|
+
new_ary
|
102
|
+
end
|
103
|
+
|
104
|
+
# Heap-sort the internal array. This reduces heap size to 1, since
|
105
|
+
# sorting the internal array destroys the heap property. Use this only if
|
106
|
+
# the heap is not used after this call and you want save speed and
|
107
|
+
# memory; otherwise use Heap#sort. See +Heap#sort+.
|
108
|
+
def sort_internal
|
109
|
+
(@array.length-1).downto(1) do |i|
|
110
|
+
swap(0,i)
|
111
|
+
@heap_size -= 1
|
112
|
+
heapify(0)
|
113
|
+
end
|
114
|
+
@array
|
115
|
+
end
|
116
|
+
|
117
|
+
# Get the first (maximum) element on the heap
|
118
|
+
def top
|
119
|
+
raise EmptyHeapException if @heap_size < 1
|
120
|
+
@array[0]
|
121
|
+
end
|
122
|
+
|
123
|
+
# Extract the first element from the heap. Will raise EmptyHeapException
|
124
|
+
# if there are no (more) elements on the heap.
|
125
|
+
def pop
|
126
|
+
raise EmptyHeapException if @heap_size < 1
|
127
|
+
@heap_size -= 1
|
128
|
+
top, @array[0] = @array[0], @array[@heap_size]
|
129
|
+
heapify(0)
|
130
|
+
top
|
131
|
+
end
|
132
|
+
|
133
|
+
# Push an element on the heap.
|
134
|
+
def push(elm)
|
135
|
+
i = @heap_size
|
136
|
+
@heap_size += 1
|
137
|
+
while i > 0 and cmp(elm, @array[(j = parent(i))])
|
138
|
+
@array[i] = @array[(i = j)]
|
139
|
+
end
|
140
|
+
@array[i] = elm
|
141
|
+
end
|
142
|
+
|
143
|
+
# Push a list of elements on the heap.
|
144
|
+
def push_all(elms)
|
145
|
+
elms.each {|e| push(e)}
|
146
|
+
end
|
147
|
+
|
148
|
+
protected
|
149
|
+
|
150
|
+
# Compare elements at the supplied indices
|
151
|
+
def cmp_idx(i,j)
|
152
|
+
cmp(@array[i], @array[j])
|
153
|
+
end
|
154
|
+
|
155
|
+
# Get the parent of the node i > 0.
|
156
|
+
def parent(i)
|
157
|
+
(i-1) >> 1 # (i-1)/2, only valid iff i > 0 !!
|
158
|
+
end
|
159
|
+
|
160
|
+
# Get the node left of node i >= 0
|
161
|
+
def left(i)
|
162
|
+
(i<<1) + 1 # 2i+1
|
163
|
+
end
|
164
|
+
|
165
|
+
# Get the node right of node i >= 0
|
166
|
+
def right(i)
|
167
|
+
(i<<1) + 2 # 2i+2
|
168
|
+
end
|
169
|
+
|
170
|
+
# Keeps an heap sorted with the smallest (largest) element on top
|
171
|
+
def heapify(i)
|
172
|
+
l = left i
|
173
|
+
top = if l < @heap_size && cmp_idx(l,i) then l else i end
|
174
|
+
r = right i
|
175
|
+
top = if r < @heap_size && cmp_idx(r,top) then r else top end
|
176
|
+
if top != i
|
177
|
+
swap(i, top)
|
178
|
+
heapify(top)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Get the size of the internal array. This may be different from the heap
|
183
|
+
# size, e.g. after +sort+ has been called.
|
184
|
+
def internal_size
|
185
|
+
@array.size
|
186
|
+
end
|
187
|
+
|
188
|
+
# Swap elements in the array
|
189
|
+
def swap(i,j)
|
190
|
+
@array[i], @array[j] = @array[j], @array[i]
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# $Id: html.rb 2004/11/01 09:19:23 transami Exp $
|
2
|
+
|
3
|
+
=begin rdoc
|
4
|
+
|
5
|
+
= HTML
|
6
|
+
|
7
|
+
Helper methods for creating HTML/XHTML documents.
|
8
|
+
|
9
|
+
== Synopsis
|
10
|
+
|
11
|
+
require 'trix/xhtml'
|
12
|
+
|
13
|
+
# [ to do ]
|
14
|
+
|
15
|
+
== Authors
|
16
|
+
|
17
|
+
* T. Onoma
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
21
|
+
require 'cgi' # Until it has its own good escape/unescape method
|
22
|
+
|
23
|
+
|
24
|
+
module HTML
|
25
|
+
|
26
|
+
def self.CGI_include!
|
27
|
+
require 'cgi'
|
28
|
+
CGI.class_eval { include XHTML }
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.FCGI_include!
|
32
|
+
require 'fcgi'
|
33
|
+
FCGI.class_eval { include XHTML }
|
34
|
+
end
|
35
|
+
|
36
|
+
################
|
37
|
+
module_functions
|
38
|
+
################
|
39
|
+
|
40
|
+
# Create an hidden input field through which an object can can be marshalled.
|
41
|
+
# This makes it very easy to pass from data betwenn requests.
|
42
|
+
def marshal_to_html(name, iobj)
|
43
|
+
data = CGI.escape(Marshal.dump(iobj))
|
44
|
+
return %Q{<input type="hidden" name="__#{name}__" value="#{data}"/>\n}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Create an hidden input field throught which an object can can be marshalled.
|
48
|
+
# This makes it very easy to pass from data betwenn requests.
|
49
|
+
def marshal_from_html(name)
|
50
|
+
return Marshal.load(CGI.unescape(self["__#{name}__"][0])) if self.params.has_key?("__#{name}__")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Are these good enough to replace CGI.escape?
|
54
|
+
|
55
|
+
# Return an html "safe" version of the string,
|
56
|
+
# where every &, < and > are replaced with appropriate entities.
|
57
|
+
def esc(str)
|
58
|
+
str.gsub(/&/,'&').gsub(/</,'<').gsub(/>/,'>')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Calls #esc, and then further replaces carriage returns and quote characters with entities.
|
62
|
+
def escformat(str)
|
63
|
+
xmlsafe(str).gsub(/[\r\n]+/,' ').gsub(%r|"|,'"').gsub(%r|'|,''')
|
64
|
+
end
|
65
|
+
|
66
|
+
# Renders an object with annotations: http://tinyurl.com/6xjnj
|
67
|
+
# Creates a table rendering +o+'s attributes.
|
68
|
+
def render_object(o, collection, edit)
|
69
|
+
r = "<table>\n"
|
70
|
+
o.instance_variables.each do |attr_name|
|
71
|
+
attr_value = o.instance_variable_get(attr_name)
|
72
|
+
attr_anns = o.class.send(attr_name[1..-1])
|
73
|
+
r << " <tr>\n"
|
74
|
+
r << " <td>" << attr_anns[:description] << "</td>\n"
|
75
|
+
r << " <td>" << text_or_input(edit, :name => "#{collection}[#{o.class.name}][#{attr_name}]", :value => attr_value) << "</td>\n"
|
76
|
+
r << " </tr>\n"
|
77
|
+
end
|
78
|
+
r << "</table>"
|
79
|
+
r
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= Infinity
|
4
|
+
|
5
|
+
A full featured Infinity class, supporting aleph levels and signed
|
6
|
+
direction. Inifinty is a multiton based on the aleph and direction
|
7
|
+
values. The conastant INFINITY is provided as the common case with
|
8
|
+
aleph=0 and direction=+1 (positive).
|
9
|
+
|
10
|
+
= Author(s)
|
11
|
+
|
12
|
+
* Thomas Sawyer
|
13
|
+
|
14
|
+
=end
|
15
|
+
|
16
|
+
|
17
|
+
require 'carat/multiton'
|
18
|
+
|
19
|
+
|
20
|
+
class Infinity < Numeric
|
21
|
+
include Multiton
|
22
|
+
|
23
|
+
def self.[](a)
|
24
|
+
self.new(a)
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :aleph, :direction
|
28
|
+
|
29
|
+
def initialize(aleph=0, direction=1)
|
30
|
+
@aleph = aleph
|
31
|
+
@direction = direction
|
32
|
+
end
|
33
|
+
|
34
|
+
def -@
|
35
|
+
self.class.instance(@aleph, @direction * -1)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_f
|
39
|
+
(1.0/0) * @direction
|
40
|
+
end
|
41
|
+
|
42
|
+
def times
|
43
|
+
loop do
|
44
|
+
yield
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def <=>(x)
|
49
|
+
return (x.kind_of?(Infinity) ? (@aleph <=> x.aleph) : @direction)
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
%Q{#{ '-' if @direction == -1 }Infinity[#{@aleph}]}
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# constant (for aleph=0)
|
59
|
+
INFINITY = Infinity.instance
|
60
|
+
|
61
|
+
|
data/lib/carat/init.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
=begin rdoc
|
3
|
+
|
4
|
+
= Init
|
5
|
+
|
6
|
+
Allows you to use #init inplace of #initialize. It does this by
|
7
|
+
aliasing initialize to init when it is defined.
|
8
|
+
|
9
|
+
== Synopsis
|
10
|
+
|
11
|
+
require 'carat/init'
|
12
|
+
|
13
|
+
class T
|
14
|
+
def init
|
15
|
+
puts "Here"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
t = T.new #=> "Here"
|
20
|
+
|
21
|
+
== Author(s)
|
22
|
+
|
23
|
+
* Thaoms Sawyer
|
24
|
+
|
25
|
+
=end
|
26
|
+
|
27
|
+
class Class
|
28
|
+
def method_added( meth )
|
29
|
+
if meth == :init
|
30
|
+
self.class_eval { alias initialize init }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,248 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
|
3
|
+
= Interval
|
4
|
+
|
5
|
+
While Ruby support the Range class out of the box, is does not quite
|
6
|
+
fullfil the role od a real Interval class. For instance, it does
|
7
|
+
not support excluding the front sentinel. This is because Range
|
8
|
+
also tries to do triple duty as a simple Sequence and as a simple Tuple-Pair,
|
9
|
+
thus limiting its potential as an Interval. The Interval class remedies
|
10
|
+
the situation by commiting to interval behavior, and then extends the class'
|
11
|
+
capabilites beyond that of the standard Range in ways that naturally
|
12
|
+
fall out of that.
|
13
|
+
|
14
|
+
Range depends on two methods: #succ and #<=>. If numeric
|
15
|
+
ranges were the only concern, those could just as well be #+ and #<=>,
|
16
|
+
but esoteric forms make that unfeasible --the obvious example being a String
|
17
|
+
range. But a proper Interval class requires mathematical continuation,
|
18
|
+
thus the Interval depends on #+ and #<=>, as well as #- as the inverse of #+.
|
19
|
+
|
20
|
+
== Synopsis
|
21
|
+
|
22
|
+
require 'carat/facet'
|
23
|
+
|
24
|
+
i = Interval.new(1,5)
|
25
|
+
i.to_a #=> [1,2,3,4,5]
|
26
|
+
|
27
|
+
i = Interval[0,5]
|
28
|
+
i.to_a(2) #=> [0,2,4]
|
29
|
+
|
30
|
+
i = Interval[1,5]
|
31
|
+
i.to_a(-1) #=> [5,4,3,2,1]
|
32
|
+
|
33
|
+
i = Interval[1,3]
|
34
|
+
i.to_a(1,2) #=> [1.0,1.5,2.0,2.5,3.0]
|
35
|
+
|
36
|
+
== Author(s)
|
37
|
+
|
38
|
+
* Thomas Sawyer
|
39
|
+
|
40
|
+
== Legal
|
41
|
+
|
42
|
+
Ruby License
|
43
|
+
Copyright (c)2005 Thomas Sawyer
|
44
|
+
|
45
|
+
=end
|
46
|
+
|
47
|
+
require 'carat/multiton'
|
48
|
+
require 'carat/enumerable-args'
|
49
|
+
#require 'carat/infinity'
|
50
|
+
|
51
|
+
class Interval
|
52
|
+
include Multiton::New
|
53
|
+
include EnumerableWithArgs
|
54
|
+
|
55
|
+
def self.[]( *args )
|
56
|
+
self.new( *args )
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(first, last, exclude_first=false, exclude_last=false )
|
60
|
+
raise ArgumentError, "bad value for interval" if first.class != last.class
|
61
|
+
@first = first
|
62
|
+
@last = last
|
63
|
+
@exclude_first = exclude_first
|
64
|
+
@exclude_last = exclude_last
|
65
|
+
@direction = (@last <=> @first)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns a two element array of first and last sentinels.
|
69
|
+
#
|
70
|
+
# (0..10).sentinels #=> [0,10]
|
71
|
+
#
|
72
|
+
def sentinels
|
73
|
+
return [@first, @last]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns the first or last sentinal of the interval.
|
77
|
+
def first ; @first ; end
|
78
|
+
def last ; @last ; end
|
79
|
+
|
80
|
+
#
|
81
|
+
def exclude_first? ; @exclude_first ; end
|
82
|
+
def exclude_last? ; @exclude_last ; end
|
83
|
+
|
84
|
+
# (IMHO) these should be deprectated
|
85
|
+
alias_method( :begin, :first )
|
86
|
+
alias_method( :end, :last )
|
87
|
+
alias_method( :exclude_begin?, :exclude_first? )
|
88
|
+
alias_method( :exclude_end?, :exclude_last? )
|
89
|
+
|
90
|
+
# Returns +true+ if the start and end sentinels are equal and the interval is closed; otherwise +false+.
|
91
|
+
def degenerate? ; @direction == 0 and ! (@exclusive_first or @exclusive_last) ; end
|
92
|
+
|
93
|
+
# Returns +true+ if the start and end sentinels are equal and the interval is open; otherwise +false+.
|
94
|
+
def null? ; @direction == 0 and @exclusive_first and @exclusive_last ; end
|
95
|
+
|
96
|
+
# Returns the direction of the interval indicated by +1, 0 or -1.
|
97
|
+
#
|
98
|
+
# (1..5).direction #=> 1
|
99
|
+
# (5..1).direction #=> -1
|
100
|
+
# (1..1).direction #=> 0
|
101
|
+
#
|
102
|
+
def direction ; @direction ; end
|
103
|
+
|
104
|
+
# Returns a new interval inclusive of of both sentinels.
|
105
|
+
def closed; Interval.new(@first, @last, true, true) ; end
|
106
|
+
|
107
|
+
# Returns a new interval exclusive of both sentinels.
|
108
|
+
def opened; Interval.new(@first, @last, true, true) ; end
|
109
|
+
|
110
|
+
# Returns a new interval with either the first or the last sentinel exclusive.
|
111
|
+
# If the parameter is false, the deafult, then the first sentinel is excluded;
|
112
|
+
# if the parameter is true, the last sentinel is excluded.
|
113
|
+
def half_closed(e=false)
|
114
|
+
e ? Interval.new(@first, @last, true, false) : Interval.new(@first, @last, false, true)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns a new interval with one of the two sentinels opened or closed
|
118
|
+
def first_closed ; Interval.new(@first, @last, false, true) ; end
|
119
|
+
def last_closed ; Interval.new(@first, @last, true, false) ; end
|
120
|
+
def first_opened ; Interval.new(@first, @last, true, false) ; end
|
121
|
+
def last_opened ; Interval.new(@first, @last, false, true) ; end
|
122
|
+
|
123
|
+
# Unary shorthands. These return a new interval exclusive of first,
|
124
|
+
# last or both sentinels, repectively.
|
125
|
+
def +@ ; Interval.new(first, last, true, false) ; end
|
126
|
+
def -@ ; Interval.new(first, last, false, true) ; end
|
127
|
+
def ~@ ; Interval.new(first, last, true, true) ; end
|
128
|
+
|
129
|
+
# Returns a new interval with the sentinels reversed.
|
130
|
+
#
|
131
|
+
# (0..10).reversed #=> 10..0
|
132
|
+
#
|
133
|
+
def reversed
|
134
|
+
Interval.new(@last, @first, true, true)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns the length of the interval as the difference between
|
138
|
+
# the first and last elements. Returns +nil+ if the sentinal objects
|
139
|
+
# do not support distance comparison (#distance).
|
140
|
+
# TODO: Add +n+ parameter to count segmentations like those produced by #each.
|
141
|
+
def distance
|
142
|
+
@last - @first
|
143
|
+
#if @last.respond_to?( :distance )
|
144
|
+
# @last.distance( @first )
|
145
|
+
#else
|
146
|
+
# #self.to_a.length
|
147
|
+
#end
|
148
|
+
end
|
149
|
+
alias_method( :length, :distance )
|
150
|
+
alias_method( :size, :distance )
|
151
|
+
|
152
|
+
# Returns the lesser of the first and last sentinals.
|
153
|
+
def min
|
154
|
+
((@first <=> @last) == -1) ? @first : @last
|
155
|
+
end
|
156
|
+
|
157
|
+
# Returns the greater of the first and last sentinals.
|
158
|
+
def max
|
159
|
+
((@first <=> @last) == 1) ? @first : @last
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns true or false if the element is part of the interval.
|
163
|
+
def include?(x)
|
164
|
+
# todo: infinity?
|
165
|
+
tf = exclude_first? ? 1 : 0
|
166
|
+
tl = exclude_last? ? -1 : 0
|
167
|
+
(x <=> first) >= tf and (x <=> last) <= tl
|
168
|
+
end
|
169
|
+
alias_method( :===, :include? )
|
170
|
+
alias_method( :member?, :include? )
|
171
|
+
|
172
|
+
=begin
|
173
|
+
# def include?(x)
|
174
|
+
# tf = exclude_first? ? 1 : 0
|
175
|
+
# tl = exclude_last? ? -1 : 0
|
176
|
+
# # if other classes handled Infinity in their <=> method
|
177
|
+
# # (which probably they should) this clause would not be required
|
178
|
+
# if first.kind_of?(InfinityClass)
|
179
|
+
# ft = ((first <=> x) <= tf)
|
180
|
+
# else
|
181
|
+
# ft = (x <=> first) >= tf
|
182
|
+
# end
|
183
|
+
# if last.kind_of?(InfinityClass)
|
184
|
+
# fl = ((last <=> x) >= tl)
|
185
|
+
# else
|
186
|
+
# fl = (x <=> last) <= tl
|
187
|
+
# end
|
188
|
+
# ft && fl
|
189
|
+
# end
|
190
|
+
=end
|
191
|
+
|
192
|
+
# Iterates over the interval, passing each _n_th element to the block.
|
193
|
+
# If n is not given then n defaults to 1. Each _n_th step is determined
|
194
|
+
# by invoking +\++ or +\-+ n, depending on the direction of the interval.
|
195
|
+
# If n is negative the iteration is preformed in reverse form end sentinal
|
196
|
+
# to front sentinal. A second parameter, d, can be given in which case
|
197
|
+
# the applied step is calculated as a fraction of the interval's length
|
198
|
+
# times n / d. This allows iteration over the whole interval in equal sized
|
199
|
+
# segments.
|
200
|
+
#
|
201
|
+
# 1..5.each { |e| ... } #=> 1 2 3 4 5
|
202
|
+
# 1..5.each(2) { |e| ... } #=> 1 3 5
|
203
|
+
# 1..5.each(1,2) { |e| ... } #=> 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
|
204
|
+
#
|
205
|
+
def each(n=1, d=nil) # :yield:
|
206
|
+
return (n < 0 ? @last : @first) if degenerate? # is this right for all values of n ?
|
207
|
+
s = d ? self.length.to_f * (n.to_f / d.to_f) : n.abs
|
208
|
+
raise "Cannot iterate over zero length steps." if s == 0
|
209
|
+
s = s * @direction
|
210
|
+
if n < 0
|
211
|
+
e = @exclude_last ? @last - s : @last
|
212
|
+
#e = @exclude_last ? @last.pred(s) : @last
|
213
|
+
t = @exlude_last ? 1 : 0
|
214
|
+
#while e.cmp(@first) >= t
|
215
|
+
while (e <=> @first) >= t
|
216
|
+
yield(e)
|
217
|
+
e -= s
|
218
|
+
#e = e.pred(s)
|
219
|
+
end
|
220
|
+
else
|
221
|
+
e = @exclude_first ? @first + s : @first
|
222
|
+
#e = @exclude_first ? @first.succ(s) : @first
|
223
|
+
t = @exlude_last ? -1 : 0
|
224
|
+
#while e.cmp(@last) <= t
|
225
|
+
while (e <=> @last) <= t
|
226
|
+
yield(e)
|
227
|
+
e += s
|
228
|
+
#e = e.succ(s)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
alias_method( :step, :each )
|
233
|
+
|
234
|
+
# Should there be a #reverse_each ?
|
235
|
+
# Since #each can now take a negative argument, this isn't really needed.
|
236
|
+
# Should it exist anyway and routed to #each?
|
237
|
+
# Also, alias_method( :reverse_step, :reverse_each )
|
238
|
+
|
239
|
+
# Compares two intervals to see if they are equal
|
240
|
+
def eql?(other)
|
241
|
+
return false unless @first == other.first
|
242
|
+
return false unless @last == other.last
|
243
|
+
return false unless @exclude_first == other.exclude_first?
|
244
|
+
return false unless @exclude_last == other.exclude_last?
|
245
|
+
true
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|