rkoans 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/CURRICULUM.md +86 -0
- data/README.md +77 -0
- data/THIRD_PARTY_NOTICES.md +30 -0
- data/exercises/about-array-assignment/about_array_assignment.rb +45 -0
- data/exercises/about-array-assignment/brief.md +11 -0
- data/exercises/about-array-assignment/hint.md +11 -0
- data/exercises/about-arrays/about_arrays.rb +77 -0
- data/exercises/about-arrays/brief.md +16 -0
- data/exercises/about-arrays/hint.md +13 -0
- data/exercises/about-asserts/about_asserts.rb +22 -0
- data/exercises/about-asserts/brief.md +22 -0
- data/exercises/about-asserts/hint.md +10 -0
- data/exercises/about-blocks/about_blocks.rb +76 -0
- data/exercises/about-blocks/brief.md +44 -0
- data/exercises/about-blocks/hint.md +7 -0
- data/exercises/about-class-methods/about_class_methods.rb +105 -0
- data/exercises/about-class-methods/brief.md +73 -0
- data/exercises/about-class-methods/hint.md +8 -0
- data/exercises/about-classes/about_classes.rb +131 -0
- data/exercises/about-classes/brief.md +73 -0
- data/exercises/about-classes/hint.md +7 -0
- data/exercises/about-constants/about_constants.rb +49 -0
- data/exercises/about-constants/brief.md +51 -0
- data/exercises/about-constants/hint.md +7 -0
- data/exercises/about-control-statements/about_control_statements.rb +152 -0
- data/exercises/about-control-statements/brief.md +9 -0
- data/exercises/about-control-statements/hint.md +7 -0
- data/exercises/about-dice-project/about_dice_project.rb +27 -0
- data/exercises/about-dice-project/brief.md +12 -0
- data/exercises/about-dice-project/hint.md +5 -0
- data/exercises/about-exceptions/about_exceptions.rb +84 -0
- data/exercises/about-exceptions/brief.md +19 -0
- data/exercises/about-exceptions/hint.md +8 -0
- data/exercises/about-extra-credit/about_extra_credit.rb +117 -0
- data/exercises/about-extra-credit/brief.md +28 -0
- data/exercises/about-extra-credit/hint.md +5 -0
- data/exercises/about-hashes/about_hashes.rb +160 -0
- data/exercises/about-hashes/brief.md +9 -0
- data/exercises/about-hashes/hint.md +8 -0
- data/exercises/about-inheritance/about_inheritance.rb +63 -0
- data/exercises/about-inheritance/brief.md +50 -0
- data/exercises/about-inheritance/hint.md +8 -0
- data/exercises/about-iteration/about_iteration.rb +96 -0
- data/exercises/about-iteration/brief.md +26 -0
- data/exercises/about-iteration/hint.md +6 -0
- data/exercises/about-keyword-arguments/about_keyword_arguments.rb +56 -0
- data/exercises/about-keyword-arguments/brief.md +28 -0
- data/exercises/about-keyword-arguments/hint.md +7 -0
- data/exercises/about-message-passing/about_message_passing.rb +112 -0
- data/exercises/about-message-passing/brief.md +59 -0
- data/exercises/about-message-passing/hint.md +8 -0
- data/exercises/about-methods/about_methods.rb +104 -0
- data/exercises/about-methods/brief.md +55 -0
- data/exercises/about-methods/hint.md +8 -0
- data/exercises/about-modules/about_modules.rb +43 -0
- data/exercises/about-modules/brief.md +44 -0
- data/exercises/about-modules/hint.md +8 -0
- data/exercises/about-nil/about_nil.rb +29 -0
- data/exercises/about-nil/brief.md +12 -0
- data/exercises/about-nil/hint.md +11 -0
- data/exercises/about-objects/about_objects.rb +51 -0
- data/exercises/about-objects/brief.md +14 -0
- data/exercises/about-objects/hint.md +12 -0
- data/exercises/about-open-classes/about_open_classes.rb +38 -0
- data/exercises/about-open-classes/brief.md +34 -0
- data/exercises/about-open-classes/hint.md +7 -0
- data/exercises/about-pattern-matching/about_pattern_matching.rb +106 -0
- data/exercises/about-pattern-matching/brief.md +124 -0
- data/exercises/about-pattern-matching/hint.md +8 -0
- data/exercises/about-proxy-object-project/about_proxy_object_project.rb +43 -0
- data/exercises/about-proxy-object-project/brief.md +10 -0
- data/exercises/about-proxy-object-project/hint.md +5 -0
- data/exercises/about-regular-expressions/about_regular_expressions.rb +174 -0
- data/exercises/about-regular-expressions/brief.md +9 -0
- data/exercises/about-regular-expressions/hint.md +8 -0
- data/exercises/about-sandwich-code/about_sandwich_code.rb +58 -0
- data/exercises/about-sandwich-code/brief.md +14 -0
- data/exercises/about-sandwich-code/hint.md +5 -0
- data/exercises/about-scope/about_scope.rb +76 -0
- data/exercises/about-scope/brief.md +35 -0
- data/exercises/about-scope/hint.md +8 -0
- data/exercises/about-scoring-project/about_scoring_project.rb +16 -0
- data/exercises/about-scoring-project/brief.md +10 -0
- data/exercises/about-scoring-project/hint.md +5 -0
- data/exercises/about-strings/about_strings.rb +142 -0
- data/exercises/about-strings/brief.md +22 -0
- data/exercises/about-strings/hint.md +11 -0
- data/exercises/about-symbols/about_symbols.rb +53 -0
- data/exercises/about-symbols/brief.md +21 -0
- data/exercises/about-symbols/hint.md +12 -0
- data/exercises/about-to-str/about_to_str.rb +49 -0
- data/exercises/about-to-str/brief.md +37 -0
- data/exercises/about-to-str/hint.md +7 -0
- data/exercises/about-triangle-project/about_triangle_project.rb +15 -0
- data/exercises/about-triangle-project/brief.md +11 -0
- data/exercises/about-triangle-project/hint.md +5 -0
- data/exercises/about-triangle-project-two/about_triangle_project_two.rb +22 -0
- data/exercises/about-triangle-project-two/brief.md +10 -0
- data/exercises/about-triangle-project-two/hint.md +5 -0
- data/exercises/about-true-and-false/about_true_and_false.rb +26 -0
- data/exercises/about-true-and-false/brief.md +22 -0
- data/exercises/about-true-and-false/hint.md +7 -0
- data/exercises/blocks-and-methods/blocks_and_methods.rb +14 -0
- data/exercises/blocks-and-methods/brief.md +8 -0
- data/exercises/blocks-and-methods/hint.md +6 -0
- data/exercises/catalog.json +61 -0
- data/exercises/class-state/brief.md +8 -0
- data/exercises/class-state/class_state.rb +39 -0
- data/exercises/class-state/hint.md +5 -0
- data/exercises/closure-capture/brief.md +8 -0
- data/exercises/closure-capture/closure_capture.rb +21 -0
- data/exercises/closure-capture/hint.md +5 -0
- data/exercises/collection-basics/brief.md +8 -0
- data/exercises/collection-basics/collection_basics.rb +16 -0
- data/exercises/collection-basics/hint.md +6 -0
- data/exercises/constant-scope/brief.md +8 -0
- data/exercises/constant-scope/constant_scope.rb +18 -0
- data/exercises/constant-scope/hint.md +5 -0
- data/exercises/core-protocols/brief.md +8 -0
- data/exercises/core-protocols/core_protocols.rb +43 -0
- data/exercises/core-protocols/hint.md +5 -0
- data/exercises/delegation/brief.md +8 -0
- data/exercises/delegation/delegation.rb +20 -0
- data/exercises/delegation/hint.md +5 -0
- data/exercises/dynamic-methods/brief.md +8 -0
- data/exercises/dynamic-methods/dynamic_methods.rb +33 -0
- data/exercises/dynamic-methods/hint.md +5 -0
- data/exercises/exception-flow/brief.md +8 -0
- data/exercises/exception-flow/exception_flow.rb +27 -0
- data/exercises/exception-flow/hint.md +5 -0
- data/exercises/heredoc-layout/brief.md +14 -0
- data/exercises/heredoc-layout/heredoc_layout.rb +25 -0
- data/exercises/heredoc-layout/hint.md +9 -0
- data/exercises/keyword-forwarding/brief.md +8 -0
- data/exercises/keyword-forwarding/hint.md +5 -0
- data/exercises/keyword-forwarding/keyword_forwarding.rb +27 -0
- data/exercises/lazy-enumeration/brief.md +8 -0
- data/exercises/lazy-enumeration/hint.md +5 -0
- data/exercises/lazy-enumeration/lazy_enumeration.rb +16 -0
- data/exercises/literals-and-operators/brief.md +20 -0
- data/exercises/literals-and-operators/hint.md +5 -0
- data/exercises/literals-and-operators/literals_and_operators.rb +15 -0
- data/exercises/method-contracts/brief.md +8 -0
- data/exercises/method-contracts/hint.md +5 -0
- data/exercises/method-contracts/method_contracts.rb +22 -0
- data/exercises/method-lookup/brief.md +8 -0
- data/exercises/method-lookup/hint.md +5 -0
- data/exercises/method-lookup/method_lookup.rb +26 -0
- data/exercises/nonlocal-exit/brief.md +8 -0
- data/exercises/nonlocal-exit/hint.md +5 -0
- data/exercises/nonlocal-exit/nonlocal_exit.rb +29 -0
- data/exercises/numbered-parameters/brief.md +18 -0
- data/exercises/numbered-parameters/hint.md +5 -0
- data/exercises/numbered-parameters/numbered_parameters.rb +18 -0
- data/exercises/numeric-precision/brief.md +8 -0
- data/exercises/numeric-precision/hint.md +5 -0
- data/exercises/numeric-precision/numeric_precision.rb +17 -0
- data/exercises/pattern-matching/brief.md +8 -0
- data/exercises/pattern-matching/hint.md +5 -0
- data/exercises/pattern-matching/pattern_matching.rb +22 -0
- data/exercises/refinement-scope/brief.md +8 -0
- data/exercises/refinement-scope/hint.md +5 -0
- data/exercises/refinement-scope/refinement_scope.rb +33 -0
- data/exercises/regexp-captures/brief.md +8 -0
- data/exercises/regexp-captures/hint.md +5 -0
- data/exercises/regexp-captures/regexp_captures.rb +25 -0
- data/exercises/runtime-context/brief.md +20 -0
- data/exercises/runtime-context/hint.md +8 -0
- data/exercises/runtime-context/runtime_context.rb +11 -0
- data/exercises/shared-rows/brief.md +8 -0
- data/exercises/shared-rows/hint.md +7 -0
- data/exercises/shared-rows/shared_rows.rb +13 -0
- data/exercises/singleton-pattern/brief.md +8 -0
- data/exercises/singleton-pattern/hint.md +5 -0
- data/exercises/singleton-pattern/singleton_pattern.rb +20 -0
- data/exercises/time-and-date/brief.md +8 -0
- data/exercises/time-and-date/hint.md +5 -0
- data/exercises/time-and-date/time_and_date.rb +21 -0
- data/exercises/visibility/brief.md +8 -0
- data/exercises/visibility/hint.md +5 -0
- data/exercises/visibility/visibility.rb +32 -0
- data/lib/rkoans/catalog.rb +31 -0
- data/lib/rkoans/checker.rb +62 -0
- data/lib/rkoans/cli.rb +79 -0
- data/lib/rkoans/error.rb +6 -0
- data/lib/rkoans/exercise.rb +50 -0
- data/lib/rkoans/keyboard.rb +51 -0
- data/lib/rkoans/progress.rb +39 -0
- data/lib/rkoans/selection.rb +31 -0
- data/lib/rkoans/session.rb +127 -0
- data/lib/rkoans/terminal_view.rb +99 -0
- data/lib/rkoans/version.rb +1 -1
- data/lib/rkoans/watcher.rb +58 -0
- data/lib/rkoans.rb +13 -3
- data/sig/about_array_assignment_acceptance_test.rbs +3 -0
- data/sig/about_arrays_acceptance_test.rbs +3 -0
- data/sig/about_asserts_command_test.rbs +4 -0
- data/sig/about_blocks_acceptance_test.rbs +3 -0
- data/sig/about_class_methods_acceptance_test.rbs +3 -0
- data/sig/about_classes_acceptance_test.rbs +3 -0
- data/sig/about_constants_acceptance_test.rbs +3 -0
- data/sig/about_control_statements_acceptance_test.rbs +3 -0
- data/sig/about_dice_project_acceptance_test.rbs +3 -0
- data/sig/about_exceptions_acceptance_test.rbs +3 -0
- data/sig/about_extra_credit_acceptance_test.rbs +5 -0
- data/sig/about_hashes_acceptance_test.rbs +3 -0
- data/sig/about_inheritance_acceptance_test.rbs +3 -0
- data/sig/about_iteration_acceptance_test.rbs +3 -0
- data/sig/about_keyword_arguments_acceptance_test.rbs +3 -0
- data/sig/about_message_passing_acceptance_test.rbs +3 -0
- data/sig/about_methods_acceptance_test.rbs +3 -0
- data/sig/about_modules_acceptance_test.rbs +3 -0
- data/sig/about_nil_acceptance_test.rbs +3 -0
- data/sig/about_objects_acceptance_test.rbs +3 -0
- data/sig/about_open_classes_acceptance_test.rbs +3 -0
- data/sig/about_pattern_matching_acceptance_test.rbs +3 -0
- data/sig/about_proxy_object_project_acceptance_test.rbs +3 -0
- data/sig/about_regular_expressions_acceptance_test.rbs +3 -0
- data/sig/about_sandwich_code_acceptance_test.rbs +3 -0
- data/sig/about_scope_acceptance_test.rbs +3 -0
- data/sig/about_scoring_project_acceptance_test.rbs +3 -0
- data/sig/about_strings_acceptance_test.rbs +3 -0
- data/sig/about_symbols_acceptance_test.rbs +3 -0
- data/sig/about_to_str_acceptance_test.rbs +3 -0
- data/sig/about_triangle_project_acceptance_test.rbs +3 -0
- data/sig/about_triangle_project_two_acceptance_test.rbs +3 -0
- data/sig/about_true_and_false_command_test.rbs +4 -0
- data/sig/catalog_error_command_test.rbs +4 -0
- data/sig/checker_test.rbs +9 -0
- data/sig/class_state_acceptance_test.rbs +3 -0
- data/sig/closure_capture_acceptance_test.rbs +3 -0
- data/sig/command_support.rbs +18 -0
- data/sig/command_test.rbs +5 -0
- data/sig/constant_scope_acceptance_test.rbs +3 -0
- data/sig/core_protocols_acceptance_test.rbs +3 -0
- data/sig/curriculum_cop_test.rbs +9 -0
- data/sig/delegation_acceptance_test.rbs +3 -0
- data/sig/dynamic_methods_acceptance_test.rbs +3 -0
- data/sig/exception_flow_acceptance_test.rbs +3 -0
- data/sig/exercise_test.rbs +3 -0
- data/sig/exercises/about_array_assignment.rbs +36 -0
- data/sig/exercises/about_arrays.rbs +51 -0
- data/sig/exercises/about_asserts.rbs +23 -0
- data/sig/exercises/about_blocks.rbs +40 -0
- data/sig/exercises/about_class_methods.rbs +62 -0
- data/sig/exercises/about_classes.rbs +88 -0
- data/sig/exercises/about_constants.rbs +53 -0
- data/sig/exercises/about_control_statements.rbs +46 -0
- data/sig/exercises/about_dice_project.rbs +16 -0
- data/sig/exercises/about_exceptions.rbs +36 -0
- data/sig/exercises/about_extra_credit.rbs +36 -0
- data/sig/exercises/about_hashes.rbs +62 -0
- data/sig/exercises/about_inheritance.rbs +50 -0
- data/sig/exercises/about_iteration.rbs +37 -0
- data/sig/exercises/about_keyword_arguments.rbs +33 -0
- data/sig/exercises/about_message_passing.rbs +68 -0
- data/sig/exercises/about_methods.rbs +68 -0
- data/sig/exercises/about_modules.rbs +38 -0
- data/sig/exercises/about_nil.rbs +23 -0
- data/sig/exercises/about_objects.rbs +38 -0
- data/sig/exercises/about_open_classes.rbs +31 -0
- data/sig/exercises/about_pattern_matching.rbs +65 -0
- data/sig/exercises/about_proxy_object_project.rbs +31 -0
- data/sig/exercises/about_regular_expressions.rbs +83 -0
- data/sig/exercises/about_sandwich_code.rbs +17 -0
- data/sig/exercises/about_scope.rbs +59 -0
- data/sig/exercises/about_scoring_project.rbs +16 -0
- data/sig/exercises/about_strings.rbs +85 -0
- data/sig/exercises/about_symbols.rbs +46 -0
- data/sig/exercises/about_to_str.rbs +36 -0
- data/sig/exercises/about_triangle_project.rbs +11 -0
- data/sig/exercises/about_triangle_project_two.rbs +12 -0
- data/sig/exercises/about_true_and_false.rbs +27 -0
- data/sig/exercises/blocks_and_methods.rbs +11 -0
- data/sig/exercises/class_state.rbs +19 -0
- data/sig/exercises/closure_capture.rbs +10 -0
- data/sig/exercises/collection_basics.rbs +6 -0
- data/sig/exercises/collection_basics_test.rbs +4 -0
- data/sig/exercises/constant_scope.rbs +11 -0
- data/sig/exercises/core_protocols.rbs +20 -0
- data/sig/exercises/delegation.rbs +14 -0
- data/sig/exercises/dynamic_methods.rbs +13 -0
- data/sig/exercises/exception_flow.rbs +11 -0
- data/sig/exercises/heredoc_layout.rbs +11 -0
- data/sig/exercises/keyword_forwarding.rbs +12 -0
- data/sig/exercises/lazy_enumeration.rbs +10 -0
- data/sig/exercises/literals_and_operators.rbs +12 -0
- data/sig/exercises/method_contracts.rbs +11 -0
- data/sig/exercises/method_lookup.rbs +16 -0
- data/sig/exercises/nonlocal_exit.rbs +14 -0
- data/sig/exercises/numbered_parameters.rbs +11 -0
- data/sig/exercises/numeric_precision.rbs +11 -0
- data/sig/exercises/pattern_matching.rbs +10 -0
- data/sig/exercises/refinement_scope.rbs +18 -0
- data/sig/exercises/regexp_captures.rbs +11 -0
- data/sig/exercises/runtime_context.rbs +23 -0
- data/sig/exercises/shared_rows.rbs +11 -0
- data/sig/exercises/singleton_pattern.rbs +14 -0
- data/sig/exercises/time_and_date.rbs +11 -0
- data/sig/exercises/visibility.rbs +18 -0
- data/sig/fixture_support.rbs +11 -0
- data/sig/help_hint_command_test.rbs +8 -0
- data/sig/heredoc_layout_acceptance_test.rbs +3 -0
- data/sig/keyboard_session_test.rbs +9 -0
- data/sig/keyword_forwarding_acceptance_test.rbs +3 -0
- data/sig/lazy_enumeration_acceptance_test.rbs +3 -0
- data/sig/literals_and_operators_acceptance_test.rbs +3 -0
- data/sig/method_contracts_acceptance_test.rbs +3 -0
- data/sig/method_lookup_acceptance_test.rbs +3 -0
- data/sig/nonlocal_exit_acceptance_test.rbs +3 -0
- data/sig/numbered_parameters_acceptance_test.rbs +3 -0
- data/sig/numeric_precision_acceptance_test.rbs +4 -0
- data/sig/packaging_test.rbs +3 -0
- data/sig/pattern_matching_acceptance_test.rbs +3 -0
- data/sig/reference_solutions_test.rbs +3 -0
- data/sig/refinement_scope_acceptance_test.rbs +3 -0
- data/sig/regexp_captures_acceptance_test.rbs +4 -0
- data/sig/rkoans/catalog.rbs +11 -0
- data/sig/rkoans/checker.rbs +22 -0
- data/sig/rkoans/cli.rbs +21 -0
- data/sig/rkoans/exercise.rbs +18 -0
- data/sig/rkoans/keyboard.rbs +13 -0
- data/sig/rkoans/progress.rbs +9 -0
- data/sig/rkoans/selection.rbs +9 -0
- data/sig/rkoans/session.rbs +30 -0
- data/sig/rkoans/terminal_view.rbs +24 -0
- data/sig/rkoans/watcher.rbs +18 -0
- data/sig/rkoans.rbs +2 -0
- data/sig/runtime_context_command_test.rbs +4 -0
- data/sig/selection_command_test.rbs +5 -0
- data/sig/session_command_test.rbs +12 -0
- data/sig/session_edge_cases_test.rbs +4 -0
- data/sig/shared_rows_acceptance_test.rbs +3 -0
- data/sig/singleton_pattern_acceptance_test.rbs +3 -0
- data/sig/time_and_date_acceptance_test.rbs +4 -0
- data/sig/visibility_acceptance_test.rbs +4 -0
- data/sig/watcher_test.rbs +3 -0
- data/solutions/about-array-assignment/about_array_assignment.rb +36 -0
- data/solutions/about-arrays/about_arrays.rb +53 -0
- data/solutions/about-asserts/about_asserts.rb +22 -0
- data/solutions/about-blocks/about_blocks.rb +30 -0
- data/solutions/about-class-methods/about_class_methods.rb +36 -0
- data/solutions/about-classes/about_classes.rb +40 -0
- data/solutions/about-constants/about_constants.rb +26 -0
- data/solutions/about-control-statements/about_control_statements.rb +35 -0
- data/solutions/about-dice-project/about_dice_project.rb +27 -0
- data/solutions/about-exceptions/about_exceptions.rb +30 -0
- data/solutions/about-extra-credit/about_extra_credit.rb +114 -0
- data/solutions/about-hashes/about_hashes.rb +52 -0
- data/solutions/about-inheritance/about_inheritance.rb +27 -0
- data/solutions/about-iteration/about_iteration.rb +31 -0
- data/solutions/about-keyword-arguments/about_keyword_arguments.rb +28 -0
- data/solutions/about-message-passing/about_message_passing.rb +38 -0
- data/solutions/about-methods/about_methods.rb +39 -0
- data/solutions/about-modules/about_modules.rb +23 -0
- data/solutions/about-nil/about_nil.rb +23 -0
- data/solutions/about-objects/about_objects.rb +34 -0
- data/solutions/about-open-classes/about_open_classes.rb +23 -0
- data/solutions/about-pattern-matching/about_pattern_matching.rb +39 -0
- data/solutions/about-proxy-object-project/about_proxy_object_project.rb +44 -0
- data/solutions/about-regular-expressions/about_regular_expressions.rb +60 -0
- data/solutions/about-sandwich-code/about_sandwich_code.rb +60 -0
- data/solutions/about-scope/about_scope.rb +33 -0
- data/solutions/about-scoring-project/about_scoring_project.rb +19 -0
- data/solutions/about-strings/about_strings.rb +56 -0
- data/solutions/about-symbols/about_symbols.rb +35 -0
- data/solutions/about-to-str/about_to_str.rb +24 -0
- data/solutions/about-triangle-project/about_triangle_project.rb +19 -0
- data/solutions/about-triangle-project-two/about_triangle_project_two.rb +25 -0
- data/solutions/about-true-and-false/about_true_and_false.rb +25 -0
- data/solutions/blocks-and-methods/blocks_and_methods.rb +14 -0
- data/solutions/class-state/class_state.rb +33 -0
- data/solutions/closure-capture/closure_capture.rb +12 -0
- data/solutions/collection-basics/collection_basics.rb +14 -0
- data/solutions/constant-scope/constant_scope.rb +18 -0
- data/solutions/core-protocols/core_protocols.rb +44 -0
- data/solutions/delegation/delegation.rb +17 -0
- data/solutions/dynamic-methods/dynamic_methods.rb +32 -0
- data/solutions/exception-flow/exception_flow.rb +34 -0
- data/solutions/heredoc-layout/heredoc_layout.rb +24 -0
- data/solutions/keyword-forwarding/keyword_forwarding.rb +26 -0
- data/solutions/lazy-enumeration/lazy_enumeration.rb +11 -0
- data/solutions/literals-and-operators/literals_and_operators.rb +22 -0
- data/solutions/method-contracts/method_contracts.rb +18 -0
- data/solutions/method-lookup/method_lookup.rb +26 -0
- data/solutions/nonlocal-exit/nonlocal_exit.rb +46 -0
- data/solutions/numbered-parameters/numbered_parameters.rb +18 -0
- data/solutions/numeric-precision/numeric_precision.rb +17 -0
- data/solutions/pattern-matching/pattern_matching.rb +17 -0
- data/solutions/refinement-scope/refinement_scope.rb +34 -0
- data/solutions/regexp-captures/regexp_captures.rb +24 -0
- data/solutions/runtime-context/runtime_context.rb +19 -0
- data/solutions/shared-rows/shared_rows.rb +13 -0
- data/solutions/singleton-pattern/singleton_pattern.rb +19 -0
- data/solutions/time-and-date/time_and_date.rb +16 -0
- data/solutions/visibility/visibility.rb +34 -0
- data/test/exercises/about_array_assignment_test.rb +87 -0
- data/test/exercises/about_arrays_test.rb +119 -0
- data/test/exercises/about_asserts_test.rb +41 -0
- data/test/exercises/about_blocks_test.rb +140 -0
- data/test/exercises/about_class_methods_test.rb +232 -0
- data/test/exercises/about_classes_test.rb +261 -0
- data/test/exercises/about_constants_test.rb +111 -0
- data/test/exercises/about_control_statements_test.rb +188 -0
- data/test/exercises/about_dice_project_test.rb +40 -0
- data/test/exercises/about_exceptions_test.rb +98 -0
- data/test/exercises/about_extra_credit_test.rb +74 -0
- data/test/exercises/about_hashes_test.rb +163 -0
- data/test/exercises/about_inheritance_test.rb +121 -0
- data/test/exercises/about_iteration_test.rb +148 -0
- data/test/exercises/about_keyword_arguments_test.rb +80 -0
- data/test/exercises/about_message_passing_test.rb +230 -0
- data/test/exercises/about_methods_test.rb +208 -0
- data/test/exercises/about_modules_test.rb +98 -0
- data/test/exercises/about_nil_test.rb +35 -0
- data/test/exercises/about_objects_test.rb +74 -0
- data/test/exercises/about_open_classes_test.rb +60 -0
- data/test/exercises/about_pattern_matching_test.rb +257 -0
- data/test/exercises/about_proxy_object_project_test.rb +75 -0
- data/test/exercises/about_regular_expressions_test.rb +243 -0
- data/test/exercises/about_sandwich_code_test.rb +82 -0
- data/test/exercises/about_scope_test.rb +123 -0
- data/test/exercises/about_scoring_project_test.rb +62 -0
- data/test/exercises/about_strings_test.rb +255 -0
- data/test/exercises/about_symbols_test.rb +120 -0
- data/test/exercises/about_to_str_test.rb +89 -0
- data/test/exercises/about_triangle_project_test.rb +29 -0
- data/test/exercises/about_triangle_project_two_test.rb +28 -0
- data/test/exercises/about_true_and_false_test.rb +43 -0
- data/test/exercises/blocks_and_methods_test.rb +22 -0
- data/test/exercises/class_state_test.rb +29 -0
- data/test/exercises/closure_capture_test.rb +29 -0
- data/test/exercises/collection_basics_test.rb +18 -0
- data/test/exercises/constant_scope_test.rb +18 -0
- data/test/exercises/core_protocols_test.rb +28 -0
- data/test/exercises/delegation_test.rb +23 -0
- data/test/exercises/dynamic_methods_test.rb +28 -0
- data/test/exercises/exception_flow_test.rb +17 -0
- data/test/exercises/heredoc_layout_test.rb +18 -0
- data/test/exercises/keyword_forwarding_test.rb +22 -0
- data/test/exercises/lazy_enumeration_test.rb +15 -0
- data/test/exercises/literals_and_operators_test.rb +25 -0
- data/test/exercises/method_contracts_test.rb +28 -0
- data/test/exercises/method_lookup_test.rb +14 -0
- data/test/exercises/nonlocal_exit_test.rb +22 -0
- data/test/exercises/numbered_parameters_test.rb +15 -0
- data/test/exercises/numeric_precision_test.rb +24 -0
- data/test/exercises/pattern_matching_test.rb +18 -0
- data/test/exercises/refinement_scope_test.rb +14 -0
- data/test/exercises/regexp_captures_test.rb +20 -0
- data/test/exercises/runtime_context_test.rb +59 -0
- data/test/exercises/shared_rows_test.rb +34 -0
- data/test/exercises/singleton_pattern_test.rb +16 -0
- data/test/exercises/time_and_date_test.rb +22 -0
- data/test/exercises/visibility_test.rb +22 -0
- metadata +471 -4
- data/Rakefile +0 -12
- data/sig/test_rkoans.rbs +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class SessionCommandTest
|
|
2
|
+
include FixtureSupport
|
|
3
|
+
def test_completion_is_persisted_and_restart_keeps_current_exercise: -> void
|
|
4
|
+
def test_next_advances_only_after_success_and_stops_at_the_last_exercise: -> void
|
|
5
|
+
def test_next_rechecks_edits_to_a_completed_exercise: -> void
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def complete_next: (IO input, IO output, String directory, String id) -> String
|
|
10
|
+
|
|
11
|
+
def with_session: (String directory) { (IO input, IO output) -> untyped } -> untyped
|
|
12
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
# Explicit array literals match the assignment examples.
|
|
8
|
+
# rubocop:disable Style/WordArray
|
|
9
|
+
|
|
10
|
+
module Exercises
|
|
11
|
+
# Predicts how array values are assigned to one or several variables.
|
|
12
|
+
class AboutArrayAssignment
|
|
13
|
+
# Returns reference predictions for the assignment examples.
|
|
14
|
+
# @return [Hash<Symbol, String | Array<String> | nil>]
|
|
15
|
+
def self.koans
|
|
16
|
+
{
|
|
17
|
+
names: ['John', 'Smith'],
|
|
18
|
+
first_name: 'John',
|
|
19
|
+
last_name: 'Smith',
|
|
20
|
+
extra_first: 'John',
|
|
21
|
+
extra_last: 'Smith',
|
|
22
|
+
splat_first: 'John',
|
|
23
|
+
splat_last: ['Smith', 'III'],
|
|
24
|
+
short_first: 'Cher',
|
|
25
|
+
short_last: nil,
|
|
26
|
+
nested_first: ['Willie', 'Rae'],
|
|
27
|
+
nested_last: 'Johnson',
|
|
28
|
+
single_first: 'John',
|
|
29
|
+
swapped_first: 'Rob',
|
|
30
|
+
swapped_last: 'Roy'
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# rubocop:enable Style/WordArray
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Explicit array literals preserve the introductory examples.
|
|
4
|
+
# rubocop:disable Style/SymbolArray
|
|
5
|
+
|
|
6
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
7
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
8
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
9
|
+
|
|
10
|
+
module Exercises
|
|
11
|
+
# Predicts array construction, indexing, slicing, ranges, and destructive operations.
|
|
12
|
+
class AboutArrays
|
|
13
|
+
# Returns reference predictions for the array experiments.
|
|
14
|
+
# Index and slice examples use [:peanut, :butter, :and, :jelly].
|
|
15
|
+
# @return [Hash<Symbol, Class | Integer | Symbol | Array | nil>]
|
|
16
|
+
# The answer table is data, not a sequence of operations.
|
|
17
|
+
def self.koans # rubocop:disable Metrics/MethodLength
|
|
18
|
+
{
|
|
19
|
+
empty_type: Array,
|
|
20
|
+
empty_size: 0,
|
|
21
|
+
second_literal: 2,
|
|
22
|
+
after_append: [1, 2, 333],
|
|
23
|
+
first_index: :peanut,
|
|
24
|
+
first_method: :peanut,
|
|
25
|
+
last_index: :jelly,
|
|
26
|
+
last_method: :jelly,
|
|
27
|
+
negative_last: :jelly,
|
|
28
|
+
negative_third: :butter,
|
|
29
|
+
slice_one: [:peanut],
|
|
30
|
+
slice_two: [:peanut, :butter],
|
|
31
|
+
slice_tail: [:and, :jelly],
|
|
32
|
+
slice_long_tail: [:and, :jelly],
|
|
33
|
+
slice_at_end_zero: [],
|
|
34
|
+
slice_at_end_long: [],
|
|
35
|
+
slice_beyond_end: nil,
|
|
36
|
+
range_type: Range,
|
|
37
|
+
inclusive_range: [1, 2, 3, 4, 5],
|
|
38
|
+
exclusive_range: [1, 2, 3, 4],
|
|
39
|
+
inclusive_slice: [:peanut, :butter, :and],
|
|
40
|
+
exclusive_slice: [:peanut, :butter],
|
|
41
|
+
negative_range_slice: [:and, :jelly],
|
|
42
|
+
after_push: [1, 2, :last],
|
|
43
|
+
popped_value: :last,
|
|
44
|
+
after_pop: [1, 2],
|
|
45
|
+
after_unshift: [:first, 1, 2],
|
|
46
|
+
shifted_value: :first,
|
|
47
|
+
after_shift: [1, 2]
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# rubocop:enable Style/SymbolArray
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# A reference implementation for comparison after completing the exercise.
|
|
9
|
+
class AboutAsserts
|
|
10
|
+
# Returns the truth values and expected sums for the introductory assertions.
|
|
11
|
+
# @return [Hash<Symbol, Boolean | Integer>]
|
|
12
|
+
def self.koans
|
|
13
|
+
{
|
|
14
|
+
truth: true,
|
|
15
|
+
with_message: true,
|
|
16
|
+
expected_value: 2,
|
|
17
|
+
better_expected_value: 2,
|
|
18
|
+
filled_value: 2
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for blocks examples.
|
|
9
|
+
class AboutBlocks
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
methods_can_take_blocks_one: 3,
|
|
16
|
+
blocks_can_be_defined_with_do_end_too_one: 3,
|
|
17
|
+
blocks_can_take_arguments_one: 'Jim',
|
|
18
|
+
methods_can_call_yield_many_times_one: %i[peanut butter and jelly],
|
|
19
|
+
methods_can_see_if_they_have_been_called_with_a_block_one: :with_block,
|
|
20
|
+
methods_can_see_if_they_have_been_called_with_a_block_two: :no_block,
|
|
21
|
+
block_can_affect_variables_in_the_code_where_they_are_created_one: :modified_in_a_block,
|
|
22
|
+
blocks_can_be_assigned_to_variables_and_called_explicitly_one: 11,
|
|
23
|
+
blocks_can_be_assigned_to_variables_and_called_explicitly_two: 11,
|
|
24
|
+
stand_alone_blocks_can_be_passed_to_methods_expecting_blocks_one: 'JIM',
|
|
25
|
+
methods_can_take_an_explicit_block_argument_one: 20,
|
|
26
|
+
methods_can_take_an_explicit_block_argument_two: 11
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for class methods examples.
|
|
9
|
+
class AboutClassMethods
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
objects_are_objects_one: true,
|
|
16
|
+
classes_are_classes_one: true,
|
|
17
|
+
classes_are_objects_too_one: true,
|
|
18
|
+
objects_have_methods_one: true,
|
|
19
|
+
classes_have_methods_one: true,
|
|
20
|
+
you_can_define_methods_on_individual_objects_one: :fidos_wag,
|
|
21
|
+
other_objects_are_not_affected_by_these_singleton_methods_one: ::NoMethodError,
|
|
22
|
+
since_classes_are_objects_you_can_define_singleton_methods_on_them_too_one: :class_level_wag,
|
|
23
|
+
class_methods_are_independent_of_instance_methods_one: :instance_level_wag,
|
|
24
|
+
class_methods_are_independent_of_instance_methods_two: :class_level_wag,
|
|
25
|
+
classes_and_instances_do_not_share_instance_variables_one: 'Fido',
|
|
26
|
+
classes_and_instances_do_not_share_instance_variables_two: nil,
|
|
27
|
+
you_can_define_class_methods_inside_the_class_one: :dogs_class_method,
|
|
28
|
+
class_statements_return_the_value_of_their_last_expression_one: 21,
|
|
29
|
+
self_while_inside_class_is_class_object_not_instance_one: true,
|
|
30
|
+
you_can_use_self_instead_of_an_explicit_reference_to_dog_one: :another_way_to_write_class_methods,
|
|
31
|
+
heres_still_another_way_to_write_class_methods_one: :still_another_way,
|
|
32
|
+
heres_an_easy_way_to_call_class_methods_from_instance_methods_one: :still_another_way
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for classes examples.
|
|
9
|
+
class AboutClasses
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans # rubocop:disable Metrics/MethodLength
|
|
14
|
+
{
|
|
15
|
+
instances_of_classes_can_be_created_with_new_one: ::AboutClassesTest::Dog,
|
|
16
|
+
instance_variables_can_be_set_by_assigning_to_them_one: [],
|
|
17
|
+
instance_variables_can_be_set_by_assigning_to_them_two: [:@name],
|
|
18
|
+
instance_variables_cannot_be_accessed_outside_the_class_one: ::NoMethodError,
|
|
19
|
+
instance_variables_cannot_be_accessed_outside_the_class_two: ::SyntaxError,
|
|
20
|
+
you_can_politely_ask_for_instance_variable_values_one: 'Fido',
|
|
21
|
+
you_can_rip_the_value_out_using_instance_eval_one: 'Fido',
|
|
22
|
+
you_can_rip_the_value_out_using_instance_eval_two: 'Fido',
|
|
23
|
+
you_can_create_accessor_methods_to_return_instance_variables_one: 'Fido',
|
|
24
|
+
attr_reader_will_automatically_define_an_accessor_one: 'Fido',
|
|
25
|
+
attr_accessor_will_automatically_define_both_read_and_write_accessors_one: 'Fido',
|
|
26
|
+
initialize_provides_initial_values_for_instance_variables_one: 'Fido',
|
|
27
|
+
args_to_new_must_match_initialize_one: ::ArgumentError,
|
|
28
|
+
different_objects_have_different_instance_variables_one: true,
|
|
29
|
+
inside_a_method_self_refers_to_the_containing_object_one: true,
|
|
30
|
+
to_s_provides_a_string_version_of_the_object_one: 'Fido',
|
|
31
|
+
to_s_is_used_in_string_interpolation_one: 'My dog is Fido',
|
|
32
|
+
inspect_provides_a_more_complete_string_version_one: "<Dog named 'Fido'>",
|
|
33
|
+
all_objects_support_to_s_and_inspect_one: '[1, 2, 3]',
|
|
34
|
+
all_objects_support_to_s_and_inspect_two: '[1, 2, 3]',
|
|
35
|
+
all_objects_support_to_s_and_inspect_three: 'STRING',
|
|
36
|
+
all_objects_support_to_s_and_inspect_four: '"STRING"'
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for constants examples.
|
|
9
|
+
class AboutConstants
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
nested_constants_may_also_be_referenced_with_relative_paths_one: 'nested',
|
|
16
|
+
top_level_constants_are_referenced_by_double_colons_one: 'top level',
|
|
17
|
+
nested_constants_are_referenced_by_their_complete_path_one: 'nested',
|
|
18
|
+
nested_constants_are_referenced_by_their_complete_path_two: 'nested',
|
|
19
|
+
nested_classes_inherit_constants_from_enclosing_classes_one: 4,
|
|
20
|
+
subclasses_inherit_constants_from_parent_classes_one: 4,
|
|
21
|
+
who_wins_with_both_nested_and_inherited_constants_one: 2,
|
|
22
|
+
who_wins_with_explicit_scoping_on_class_definition_one: 4
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for control statements examples.
|
|
9
|
+
class AboutControlStatements
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
if_then_else_statements_one: :true_value,
|
|
16
|
+
if_then_statements_one: :true_value,
|
|
17
|
+
if_statements_return_values_one: :true_value,
|
|
18
|
+
if_statements_return_values_two: :false_value,
|
|
19
|
+
if_statements_with_no_else_with_false_condition_return_value_one: nil,
|
|
20
|
+
condition_operators_one: :true_value,
|
|
21
|
+
condition_operators_two: :false_value,
|
|
22
|
+
if_statement_modifiers_one: :true_value,
|
|
23
|
+
unless_statement_one: :false_value,
|
|
24
|
+
unless_statement_evaluate_true_one: :default_value,
|
|
25
|
+
unless_statement_modifier_one: :false_value,
|
|
26
|
+
while_statement_one: 3_628_800,
|
|
27
|
+
break_statement_one: 3_628_800,
|
|
28
|
+
break_statement_returns_values_one: 2,
|
|
29
|
+
next_statement_one: [1, 3, 5, 7, 9],
|
|
30
|
+
for_statement_one: %w[FISH AND CHIPS],
|
|
31
|
+
times_statement_one: 10
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# A set of dice with stable values until the next roll.
|
|
9
|
+
class AboutDiceProject
|
|
10
|
+
# Stores the latest roll from an injectable random source.
|
|
11
|
+
class DiceSet
|
|
12
|
+
attr_reader :values
|
|
13
|
+
|
|
14
|
+
# @param random [Random] source of uniform six-sided die values
|
|
15
|
+
def initialize(random: Random.new)
|
|
16
|
+
@random = random
|
|
17
|
+
@values = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @param count [Integer] number of dice to roll
|
|
21
|
+
# @return [Array<Integer>] freshly rolled values
|
|
22
|
+
def roll(count)
|
|
23
|
+
@values = Array.new(count) { @random.rand(1..6) }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for exceptions examples.
|
|
9
|
+
class AboutExceptions
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
exceptions_inherit_from_Exception_one: ::RuntimeError,
|
|
16
|
+
exceptions_inherit_from_Exception_two: ::StandardError,
|
|
17
|
+
exceptions_inherit_from_Exception_three: ::Exception,
|
|
18
|
+
exceptions_inherit_from_Exception_four: ::Object,
|
|
19
|
+
rescue_clause_one: :exception_handled,
|
|
20
|
+
rescue_clause_two: true,
|
|
21
|
+
rescue_clause_three: true,
|
|
22
|
+
rescue_clause_four: 'Oops',
|
|
23
|
+
raising_a_particular_error_one: :exception_handled,
|
|
24
|
+
raising_a_particular_error_two: 'My Message',
|
|
25
|
+
ensure_clause_one: :always_run,
|
|
26
|
+
asserting_an_error_is_raised_one: ::AboutExceptionsTest::MySpecialError
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# A deterministic Greed game engine; callers supply rolls and decide when to bank.
|
|
9
|
+
class AboutExtraCredit
|
|
10
|
+
# Tracks one player and the entry threshold.
|
|
11
|
+
class Player
|
|
12
|
+
attr_reader :name, :score
|
|
13
|
+
|
|
14
|
+
# @param name [String] player name
|
|
15
|
+
def initialize(name)
|
|
16
|
+
@name = name
|
|
17
|
+
@score = 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Bank a turn once the player has entered with at least 300 points.
|
|
21
|
+
# @return [Integer] total score
|
|
22
|
+
def bank(points)
|
|
23
|
+
@score += points if @score.positive? || points >= 300
|
|
24
|
+
@score
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Coordinates turn order, banking, busts and the final round.
|
|
29
|
+
class Game
|
|
30
|
+
attr_reader :players, :current
|
|
31
|
+
|
|
32
|
+
# @param names [Array<String>] at least two players, in turn order
|
|
33
|
+
def initialize(names)
|
|
34
|
+
raise ArgumentError, 'at least two players required' if names.size < 2
|
|
35
|
+
|
|
36
|
+
@players = names.map { |name| Player.new(name) }
|
|
37
|
+
@current = 0
|
|
38
|
+
@remaining = nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Play the current player's complete turn; ending the rolls banks the points.
|
|
42
|
+
# @param rolls [Array<Array<Integer>>] ordered rolls, with legal remaining-dice counts
|
|
43
|
+
# @return [Integer] that player's total score after this turn
|
|
44
|
+
def play_turn(rolls)
|
|
45
|
+
raise 'game finished' if finished?
|
|
46
|
+
|
|
47
|
+
total = players[current].bank(turn_points(rolls))
|
|
48
|
+
advance(total)
|
|
49
|
+
total
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [Boolean] all other players have taken their final turn
|
|
53
|
+
def finished?
|
|
54
|
+
@remaining&.zero? || false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @return [Player, nil] highest-scoring player after the final round; first in a tie
|
|
58
|
+
def winner
|
|
59
|
+
players.max_by(&:score) if finished?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# @return [Integer] accumulated turn points, or zero after a bust
|
|
65
|
+
def turn_points(rolls)
|
|
66
|
+
raise ArgumentError, 'a turn needs at least one roll' if rolls.empty?
|
|
67
|
+
|
|
68
|
+
points = 0
|
|
69
|
+
count = 5
|
|
70
|
+
rolls.each_with_index do |roll, index|
|
|
71
|
+
validate_roll(roll, count)
|
|
72
|
+
scored, unused = score_roll(roll)
|
|
73
|
+
if scored.zero?
|
|
74
|
+
raise ArgumentError, 'turn ends on a bust' unless index == rolls.size - 1
|
|
75
|
+
|
|
76
|
+
return 0
|
|
77
|
+
end
|
|
78
|
+
points += scored
|
|
79
|
+
count = unused.zero? ? 5 : unused
|
|
80
|
+
end
|
|
81
|
+
points
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @return [void] reject malformed rolls before changing game state
|
|
85
|
+
def validate_roll(roll, count)
|
|
86
|
+
valid = roll.size == count && roll.all? { |face| face.is_a?(Integer) && (1..6).cover?(face) }
|
|
87
|
+
raise ArgumentError, 'invalid dice count or face' unless valid
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @return [Array<Integer>] points and the number of non-scoring dice
|
|
91
|
+
def score_roll(roll)
|
|
92
|
+
points = 0
|
|
93
|
+
unused = 0
|
|
94
|
+
roll.tally.each do |face, amount|
|
|
95
|
+
triples, singles = amount.divmod(3)
|
|
96
|
+
points += triples * (face == 1 ? 1000 : face * 100)
|
|
97
|
+
points += singles * { 1 => 100, 5 => 50 }.fetch(face, 0)
|
|
98
|
+
unused += singles unless [1, 5].include?(face)
|
|
99
|
+
end
|
|
100
|
+
[points, unused]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Start the final round once, then give each remaining player exactly one turn.
|
|
104
|
+
def advance(total)
|
|
105
|
+
if @remaining
|
|
106
|
+
@remaining -= 1
|
|
107
|
+
elsif total >= 3000
|
|
108
|
+
@remaining = players.size - 1
|
|
109
|
+
end
|
|
110
|
+
@current = (current + 1) % players.size
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for hashes examples.
|
|
9
|
+
class AboutHashes
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans # rubocop:disable Metrics/MethodLength
|
|
14
|
+
{
|
|
15
|
+
creating_hashes_one: ::Hash,
|
|
16
|
+
creating_hashes_two: {},
|
|
17
|
+
creating_hashes_three: 0,
|
|
18
|
+
hash_literals_one: 2,
|
|
19
|
+
accessing_hashes_one: 'uno',
|
|
20
|
+
accessing_hashes_two: 'dos',
|
|
21
|
+
accessing_hashes_three: nil,
|
|
22
|
+
accessing_hashes_with_fetch_one: 'uno',
|
|
23
|
+
accessing_hashes_with_fetch_two: ::KeyError,
|
|
24
|
+
changing_hashes_one: { one: 'eins', two: 'dos' },
|
|
25
|
+
hash_is_unordered_one: true,
|
|
26
|
+
hash_keys_one: 2,
|
|
27
|
+
hash_keys_two: true,
|
|
28
|
+
hash_keys_three: true,
|
|
29
|
+
hash_keys_four: ::Array,
|
|
30
|
+
hash_values_one: 2,
|
|
31
|
+
hash_values_two: true,
|
|
32
|
+
hash_values_three: true,
|
|
33
|
+
hash_values_four: ::Array,
|
|
34
|
+
combining_hashes_one: true,
|
|
35
|
+
combining_hashes_two: true,
|
|
36
|
+
default_value_one: 1,
|
|
37
|
+
default_value_two: nil,
|
|
38
|
+
default_value_three: 1,
|
|
39
|
+
default_value_four: 'dos',
|
|
40
|
+
default_value_is_the_same_object_one: %w[uno dos],
|
|
41
|
+
default_value_is_the_same_object_two: %w[uno dos],
|
|
42
|
+
default_value_is_the_same_object_three: %w[uno dos],
|
|
43
|
+
default_value_is_the_same_object_four: true,
|
|
44
|
+
default_value_with_block_one: ['uno'],
|
|
45
|
+
default_value_with_block_two: ['dos'],
|
|
46
|
+
default_value_with_block_three: [],
|
|
47
|
+
default_value_attribute_one: nil,
|
|
48
|
+
default_value_attribute_two: 'peanut'
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for inheritance examples.
|
|
9
|
+
class AboutInheritance
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
subclasses_have_the_parent_as_an_ancestor_one: true,
|
|
16
|
+
all_classes_ultimately_inherit_from_object_one: true,
|
|
17
|
+
subclasses_inherit_behavior_from_parent_class_one: 'Chico',
|
|
18
|
+
subclasses_add_new_behavior_one: :happy,
|
|
19
|
+
subclasses_add_new_behavior_two: ::NoMethodError,
|
|
20
|
+
subclasses_can_modify_existing_behavior_one: 'yip',
|
|
21
|
+
subclasses_can_modify_existing_behavior_two: 'WOOF',
|
|
22
|
+
subclasses_can_invoke_parent_behavior_via_super_one: 'WOOF, GROWL',
|
|
23
|
+
super_does_not_work_cross_method_one: ::NoMethodError
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for iteration examples.
|
|
9
|
+
class AboutIteration
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
each_is_a_method_on_arrays_one: true,
|
|
16
|
+
iterating_with_each_one: 6,
|
|
17
|
+
each_can_use_curly_brace_blocks_too_one: 6,
|
|
18
|
+
break_works_with_each_style_iterations_one: 6,
|
|
19
|
+
collect_transforms_elements_of_an_array_one: [11, 12, 13],
|
|
20
|
+
collect_transforms_elements_of_an_array_two: [11, 12, 13],
|
|
21
|
+
select_selects_certain_items_from_an_array_one: [2, 4, 6],
|
|
22
|
+
select_selects_certain_items_from_an_array_two: [2, 4, 6],
|
|
23
|
+
find_locates_the_first_element_matching_a_criteria_one: 'Clarence',
|
|
24
|
+
inject_will_blow_your_mind_one: 9,
|
|
25
|
+
inject_will_blow_your_mind_two: 24,
|
|
26
|
+
all_iteration_methods_work_on_any_collection_not_just_arrays_one: [11, 12, 13],
|
|
27
|
+
all_iteration_methods_work_on_any_collection_not_just_arrays_two: %w[THIS IS A TEST]
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-License-Identifier: CC-BY-NC-SA-3.0
|
|
4
|
+
# Adapted from Ruby Koans by Jim Weirich and Joe O'Brien.
|
|
5
|
+
# See THIRD_PARTY_NOTICES.md for attribution and license terms.
|
|
6
|
+
|
|
7
|
+
module Exercises
|
|
8
|
+
# Predictions for keyword arguments examples.
|
|
9
|
+
class AboutKeywordArguments
|
|
10
|
+
# Returns reference predictions for the examples.
|
|
11
|
+
# @return [Hash<Symbol, Object>]
|
|
12
|
+
# This method is an answer table, not a sequence of operations.
|
|
13
|
+
def self.koans
|
|
14
|
+
{
|
|
15
|
+
keyword_arguments_one: ::Array,
|
|
16
|
+
keyword_arguments_two: [1, 'two'],
|
|
17
|
+
keyword_arguments_three: %w[one two],
|
|
18
|
+
keyword_arguments_four: [1, 2],
|
|
19
|
+
keyword_arguments_with_wrong_number_of_arguments_one: ::ArgumentError,
|
|
20
|
+
keyword_arguments_with_wrong_number_of_arguments_two: 'wrong number of arguments',
|
|
21
|
+
mandatory_keyword_arguments_one: %w[one two],
|
|
22
|
+
mandatory_keyword_arguments_two: [1, 2],
|
|
23
|
+
mandatory_keyword_arguments_without_mandatory_argument_one: ::ArgumentError,
|
|
24
|
+
mandatory_keyword_arguments_without_mandatory_argument_two: 'missing keyword'
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|