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,105 @@
|
|
|
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
|
+
# Replace each :fill_me_in with the result of the described expression.
|
|
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.
|
|
16
|
+
# fido = Dog.new
|
|
17
|
+
# assert_equal __, fido.is_a?(Object)
|
|
18
|
+
# Predict: fido.is_a?(Object)
|
|
19
|
+
objects_are_objects_one: :fill_me_in,
|
|
20
|
+
# Classes are classes.
|
|
21
|
+
# assert_equal __, Dog.is_a?(Class)
|
|
22
|
+
# Predict: Dog.is_a?(Class)
|
|
23
|
+
classes_are_classes_one: :fill_me_in,
|
|
24
|
+
# Classes are objects too.
|
|
25
|
+
# assert_equal __, Dog.is_a?(Object)
|
|
26
|
+
# Predict: Dog.is_a?(Object)
|
|
27
|
+
classes_are_objects_too_one: :fill_me_in,
|
|
28
|
+
# Objects have methods.
|
|
29
|
+
# fido = Dog.new
|
|
30
|
+
# assert_equal __, fido.methods.any?
|
|
31
|
+
# Predict: fido.methods.any?
|
|
32
|
+
objects_have_methods_one: :fill_me_in,
|
|
33
|
+
# Classes have methods.
|
|
34
|
+
# assert_equal __, Dog.methods.any?
|
|
35
|
+
# Predict: Dog.methods.any?
|
|
36
|
+
classes_have_methods_one: :fill_me_in,
|
|
37
|
+
# You can define methods on individual objects.
|
|
38
|
+
# fido = Dog.new
|
|
39
|
+
# def fido.wag
|
|
40
|
+
# :fidos_wag
|
|
41
|
+
# end
|
|
42
|
+
# assert_equal __, fido.wag
|
|
43
|
+
# Predict: fido.wag
|
|
44
|
+
you_can_define_methods_on_individual_objects_one: :fill_me_in,
|
|
45
|
+
# Other objects are not affected by these singleton methods.
|
|
46
|
+
# fido = Dog.new
|
|
47
|
+
# rover = Dog.new
|
|
48
|
+
# def fido.wag
|
|
49
|
+
# :fidos_wag
|
|
50
|
+
# end
|
|
51
|
+
# assert_raise(___) do
|
|
52
|
+
# rover.wag
|
|
53
|
+
# end
|
|
54
|
+
# Predict: exception class from: rover.wag
|
|
55
|
+
other_objects_are_not_affected_by_these_singleton_methods_one: :fill_me_in,
|
|
56
|
+
# Since classes are objects you can define singleton methods on them too.
|
|
57
|
+
# assert_equal __, Dog2.wag
|
|
58
|
+
# Predict: Dog2.wag
|
|
59
|
+
since_classes_are_objects_you_can_define_singleton_methods_on_them_too_one: :fill_me_in,
|
|
60
|
+
# Class methods are independent of instance methods.
|
|
61
|
+
# fido = Dog2.new
|
|
62
|
+
# assert_equal __, fido.wag
|
|
63
|
+
# assert_equal __, Dog2.wag
|
|
64
|
+
# Predict: fido.wag
|
|
65
|
+
class_methods_are_independent_of_instance_methods_one: :fill_me_in,
|
|
66
|
+
# Predict: Dog2.wag
|
|
67
|
+
class_methods_are_independent_of_instance_methods_two: :fill_me_in,
|
|
68
|
+
# Classes and instances do not share instance variables.
|
|
69
|
+
# fido = Dog.new
|
|
70
|
+
# fido.name = "Fido"
|
|
71
|
+
# assert_equal __, fido.name
|
|
72
|
+
# assert_equal __, Dog.name
|
|
73
|
+
# Predict: fido.name
|
|
74
|
+
classes_and_instances_do_not_share_instance_variables_one: :fill_me_in,
|
|
75
|
+
# Predict: Dog.name
|
|
76
|
+
classes_and_instances_do_not_share_instance_variables_two: :fill_me_in,
|
|
77
|
+
# You can define class methods inside the class.
|
|
78
|
+
# assert_equal __, Dog.a_class_method
|
|
79
|
+
# Predict: Dog.a_class_method
|
|
80
|
+
you_can_define_class_methods_inside_the_class_one: :fill_me_in,
|
|
81
|
+
# Class statements return the value of their last expression.
|
|
82
|
+
# assert_equal __, LastExpressionInClassStatement
|
|
83
|
+
# Predict: LastExpressionInClassStatement
|
|
84
|
+
class_statements_return_the_value_of_their_last_expression_one: :fill_me_in,
|
|
85
|
+
# Self while inside class is class object not instance.
|
|
86
|
+
# assert_equal __, Dog == SelfInsideOfClassStatement
|
|
87
|
+
# Predict: Dog == SelfInsideOfClassStatement
|
|
88
|
+
self_while_inside_class_is_class_object_not_instance_one: :fill_me_in,
|
|
89
|
+
# You can use self instead of an explicit reference to dog.
|
|
90
|
+
# assert_equal __, Dog.class_method2
|
|
91
|
+
# Predict: Dog.class_method2
|
|
92
|
+
you_can_use_self_instead_of_an_explicit_reference_to_dog_one: :fill_me_in,
|
|
93
|
+
# Heres still another way to write class methods.
|
|
94
|
+
# assert_equal __, Dog.another_class_method
|
|
95
|
+
# Predict: Dog.another_class_method
|
|
96
|
+
heres_still_another_way_to_write_class_methods_one: :fill_me_in,
|
|
97
|
+
# Heres an easy way to call class methods from instance methods.
|
|
98
|
+
# fido = Dog.new
|
|
99
|
+
# assert_equal __, fido.class.another_class_method
|
|
100
|
+
# Predict: fido.class.another_class_method
|
|
101
|
+
heres_an_easy_way_to_call_class_methods_from_instance_methods_one: :fill_me_in
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# About Class Methods
|
|
2
|
+
|
|
3
|
+
Replace each `:fill_me_in` in `about_class_methods.rb` with the predicted result.
|
|
4
|
+
Each field identifies its example. Run the checks after edits to investigate the
|
|
5
|
+
next prediction. Answers include the Ruby values and exception classes shown by
|
|
6
|
+
the examples. Read the setup comments before evaluating an expression.
|
|
7
|
+
|
|
8
|
+
## Example definitions
|
|
9
|
+
|
|
10
|
+
These definitions supply the objects and methods used by the prediction examples.
|
|
11
|
+
They run in the check class `AboutClassMethodsTest`.
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
class Dog
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Dog2
|
|
18
|
+
def wag
|
|
19
|
+
:instance_level_wag
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Dog
|
|
24
|
+
attr_accessor :name
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Dog
|
|
28
|
+
def Dog.a_class_method
|
|
29
|
+
:dogs_class_method
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Dog
|
|
34
|
+
21
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Dog
|
|
38
|
+
self
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Dog
|
|
42
|
+
def self.class_method2
|
|
43
|
+
:another_way_to_write_class_methods
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Dog
|
|
48
|
+
class << self
|
|
49
|
+
def another_class_method
|
|
50
|
+
:still_another_way
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def fido.wag
|
|
56
|
+
:fidos_wag
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def fido.wag
|
|
60
|
+
:fidos_wag
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def Dog2.wag
|
|
64
|
+
:class_level_wag
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def Dog.name
|
|
68
|
+
@name
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
73
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Hint
|
|
2
|
+
|
|
3
|
+
Classes are objects too. A class method belongs to the class object, while
|
|
4
|
+
an instance method belongs to instances. Class-object instance variables are
|
|
5
|
+
separate from an instance's variables.
|
|
6
|
+
|
|
7
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
8
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
# Replace each :fill_me_in with the result of the described expression.
|
|
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.
|
|
16
|
+
# fido = Dog.new
|
|
17
|
+
# assert_equal __, fido.class
|
|
18
|
+
# Predict: fido.class
|
|
19
|
+
instances_of_classes_can_be_created_with_new_one: :fill_me_in,
|
|
20
|
+
# Instance variables can be set by assigning to them.
|
|
21
|
+
# fido = Dog2.new
|
|
22
|
+
# assert_equal __, fido.instance_variables
|
|
23
|
+
# fido.set_name("Fido")
|
|
24
|
+
# assert_equal __, fido.instance_variables
|
|
25
|
+
# Predict: fido.instance_variables
|
|
26
|
+
instance_variables_can_be_set_by_assigning_to_them_one: :fill_me_in,
|
|
27
|
+
# Predict: fido.instance_variables
|
|
28
|
+
instance_variables_can_be_set_by_assigning_to_them_two: :fill_me_in,
|
|
29
|
+
# Instance variables cannot be accessed outside the class.
|
|
30
|
+
# fido = Dog2.new
|
|
31
|
+
# fido.set_name("Fido")
|
|
32
|
+
# assert_raise(___) do
|
|
33
|
+
# fido.name
|
|
34
|
+
# end
|
|
35
|
+
# assert_raise(___) do
|
|
36
|
+
# eval "fido.@name"
|
|
37
|
+
# NOTE: Using eval because the above line is a syntax error.
|
|
38
|
+
# end
|
|
39
|
+
# Predict: exception class from: fido.name
|
|
40
|
+
instance_variables_cannot_be_accessed_outside_the_class_one: :fill_me_in,
|
|
41
|
+
# Predict: exception class from: eval "fido.@name"
|
|
42
|
+
instance_variables_cannot_be_accessed_outside_the_class_two: :fill_me_in,
|
|
43
|
+
# You can politely ask for instance variable values.
|
|
44
|
+
# fido = Dog2.new
|
|
45
|
+
# fido.set_name("Fido")
|
|
46
|
+
# assert_equal __, fido.instance_variable_get("@name")
|
|
47
|
+
# Predict: fido.instance_variable_get("@name")
|
|
48
|
+
you_can_politely_ask_for_instance_variable_values_one: :fill_me_in,
|
|
49
|
+
# You can rip the value out using instance eval.
|
|
50
|
+
# fido = Dog2.new
|
|
51
|
+
# fido.set_name("Fido")
|
|
52
|
+
# assert_equal __, fido.instance_eval("@name") # string version
|
|
53
|
+
# assert_equal __, fido.instance_eval { @name }
|
|
54
|
+
# Predict: fido.instance_eval("@name")
|
|
55
|
+
you_can_rip_the_value_out_using_instance_eval_one: :fill_me_in,
|
|
56
|
+
# Predict: fido.instance_eval { @name }
|
|
57
|
+
you_can_rip_the_value_out_using_instance_eval_two: :fill_me_in,
|
|
58
|
+
# You can create accessor methods to return instance variables.
|
|
59
|
+
# fido = Dog3.new
|
|
60
|
+
# fido.set_name("Fido")
|
|
61
|
+
# assert_equal __, fido.name
|
|
62
|
+
# Predict: fido.name
|
|
63
|
+
you_can_create_accessor_methods_to_return_instance_variables_one: :fill_me_in,
|
|
64
|
+
# Attr reader will automatically define an accessor.
|
|
65
|
+
# fido = Dog4.new
|
|
66
|
+
# fido.set_name("Fido")
|
|
67
|
+
# assert_equal __, fido.name
|
|
68
|
+
# Predict: fido.name
|
|
69
|
+
attr_reader_will_automatically_define_an_accessor_one: :fill_me_in,
|
|
70
|
+
# Attr accessor will automatically define both read and write accessors.
|
|
71
|
+
# fido = Dog5.new
|
|
72
|
+
# fido.name = "Fido"
|
|
73
|
+
# assert_equal __, fido.name
|
|
74
|
+
# Predict: fido.name
|
|
75
|
+
attr_accessor_will_automatically_define_both_read_and_write_accessors_one: :fill_me_in,
|
|
76
|
+
# Initialize provides initial values for instance variables.
|
|
77
|
+
# fido = Dog6.new("Fido")
|
|
78
|
+
# assert_equal __, fido.name
|
|
79
|
+
# Predict: fido.name
|
|
80
|
+
initialize_provides_initial_values_for_instance_variables_one: :fill_me_in,
|
|
81
|
+
# Args to new must match initialize.
|
|
82
|
+
# assert_raise(___) do
|
|
83
|
+
# Dog6.new
|
|
84
|
+
# end
|
|
85
|
+
# Predict: exception class from: Dog6.new
|
|
86
|
+
args_to_new_must_match_initialize_one: :fill_me_in,
|
|
87
|
+
# Different objects have different instance variables.
|
|
88
|
+
# fido = Dog6.new("Fido")
|
|
89
|
+
# rover = Dog6.new("Rover")
|
|
90
|
+
# assert_equal __, rover.name != fido.name
|
|
91
|
+
# Predict: rover.name != fido.name
|
|
92
|
+
different_objects_have_different_instance_variables_one: :fill_me_in,
|
|
93
|
+
# Inside a method self refers to the containing object.
|
|
94
|
+
# fido = Dog7.new("Fido")
|
|
95
|
+
# fidos_self = fido.get_self
|
|
96
|
+
# assert_equal __, fidos_self.equal?(fido)
|
|
97
|
+
# Predict: fidos_self.equal?(fido)
|
|
98
|
+
inside_a_method_self_refers_to_the_containing_object_one: :fill_me_in,
|
|
99
|
+
# To s provides a string version of the object.
|
|
100
|
+
# fido = Dog7.new("Fido")
|
|
101
|
+
# assert_equal __, fido.to_s
|
|
102
|
+
# Predict: fido.to_s
|
|
103
|
+
to_s_provides_a_string_version_of_the_object_one: :fill_me_in,
|
|
104
|
+
# To s is used in string interpolation.
|
|
105
|
+
# fido = Dog7.new("Fido")
|
|
106
|
+
# assert_equal __, "My dog is #{fido}"
|
|
107
|
+
# Predict: "My dog is #{fido}"
|
|
108
|
+
to_s_is_used_in_string_interpolation_one: :fill_me_in,
|
|
109
|
+
# Inspect provides a more complete string version.
|
|
110
|
+
# fido = Dog7.new("Fido")
|
|
111
|
+
# assert_equal __, fido.inspect
|
|
112
|
+
# Predict: fido.inspect
|
|
113
|
+
inspect_provides_a_more_complete_string_version_one: :fill_me_in,
|
|
114
|
+
# All objects support to s and inspect.
|
|
115
|
+
# array = [1,2,3]
|
|
116
|
+
# assert_equal __, array.to_s
|
|
117
|
+
# assert_equal __, array.inspect
|
|
118
|
+
# assert_equal __, "STRING".to_s
|
|
119
|
+
# assert_equal __, "STRING".inspect
|
|
120
|
+
# Predict: array.to_s
|
|
121
|
+
all_objects_support_to_s_and_inspect_one: :fill_me_in,
|
|
122
|
+
# Predict: array.inspect
|
|
123
|
+
all_objects_support_to_s_and_inspect_two: :fill_me_in,
|
|
124
|
+
# Predict: "STRING".to_s
|
|
125
|
+
all_objects_support_to_s_and_inspect_three: :fill_me_in,
|
|
126
|
+
# Predict: "STRING".inspect
|
|
127
|
+
all_objects_support_to_s_and_inspect_four: :fill_me_in
|
|
128
|
+
}
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# About Classes
|
|
2
|
+
|
|
3
|
+
Replace each `:fill_me_in` in `about_classes.rb` with the predicted result.
|
|
4
|
+
Each field identifies its example. Run the checks after edits to investigate the
|
|
5
|
+
next prediction. Answers include the Ruby values and exception classes shown by
|
|
6
|
+
the examples. Read the setup comments before evaluating an expression.
|
|
7
|
+
|
|
8
|
+
## Example definitions
|
|
9
|
+
|
|
10
|
+
These definitions supply the objects and methods used by the prediction examples.
|
|
11
|
+
They run in the check class `AboutClassesTest`.
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
class Dog
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Dog2
|
|
18
|
+
def set_name(a_name)
|
|
19
|
+
@name = a_name
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Dog3
|
|
24
|
+
def set_name(a_name)
|
|
25
|
+
@name = a_name
|
|
26
|
+
end
|
|
27
|
+
def name
|
|
28
|
+
@name
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class Dog4
|
|
33
|
+
attr_reader :name
|
|
34
|
+
|
|
35
|
+
def set_name(a_name)
|
|
36
|
+
@name = a_name
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Dog5
|
|
41
|
+
attr_accessor :name
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Dog6
|
|
45
|
+
attr_reader :name
|
|
46
|
+
def initialize(initial_name)
|
|
47
|
+
@name = initial_name
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Dog7
|
|
52
|
+
attr_reader :name
|
|
53
|
+
|
|
54
|
+
def initialize(initial_name)
|
|
55
|
+
@name = initial_name
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def get_self
|
|
59
|
+
self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def to_s
|
|
63
|
+
@name
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def inspect
|
|
67
|
+
"<Dog named '#{name}'>"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
73
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Hint
|
|
2
|
+
|
|
3
|
+
Follow construction, instance variables, accessors, and the receiver `self`.
|
|
4
|
+
Each object owns its instance variables. Compare `to_s` with `inspect`.
|
|
5
|
+
|
|
6
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
7
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
# Replace each :fill_me_in with the result of the described expression.
|
|
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.
|
|
16
|
+
# assert_equal __, C
|
|
17
|
+
# Predict: C
|
|
18
|
+
nested_constants_may_also_be_referenced_with_relative_paths_one: :fill_me_in,
|
|
19
|
+
# Top level constants are referenced by double colons.
|
|
20
|
+
# assert_equal __, ::C
|
|
21
|
+
# Predict: ::C
|
|
22
|
+
top_level_constants_are_referenced_by_double_colons_one: :fill_me_in,
|
|
23
|
+
# Nested constants are referenced by their complete path.
|
|
24
|
+
# assert_equal __, AboutConstantsTest::C
|
|
25
|
+
# assert_equal __, ::AboutConstantsTest::C
|
|
26
|
+
# Predict: AboutConstantsTest::C
|
|
27
|
+
nested_constants_are_referenced_by_their_complete_path_one: :fill_me_in,
|
|
28
|
+
# Predict: ::AboutConstantsTest::C
|
|
29
|
+
nested_constants_are_referenced_by_their_complete_path_two: :fill_me_in,
|
|
30
|
+
# Nested classes inherit constants from enclosing classes.
|
|
31
|
+
# assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal
|
|
32
|
+
# Predict: Animal::NestedAnimal.new.legs_in_nested_animal
|
|
33
|
+
nested_classes_inherit_constants_from_enclosing_classes_one: :fill_me_in,
|
|
34
|
+
# Subclasses inherit constants from parent classes.
|
|
35
|
+
# assert_equal __, Reptile.new.legs_in_reptile
|
|
36
|
+
# Predict: Reptile.new.legs_in_reptile
|
|
37
|
+
subclasses_inherit_constants_from_parent_classes_one: :fill_me_in,
|
|
38
|
+
# Who wins with both nested and inherited constants.
|
|
39
|
+
# assert_equal __, MyAnimals::Bird.new.legs_in_bird
|
|
40
|
+
# Predict: MyAnimals::Bird.new.legs_in_bird
|
|
41
|
+
who_wins_with_both_nested_and_inherited_constants_one: :fill_me_in,
|
|
42
|
+
# Who wins with explicit scoping on class definition.
|
|
43
|
+
# assert_equal __, MyAnimals::Oyster.new.legs_in_oyster
|
|
44
|
+
# Predict: MyAnimals::Oyster.new.legs_in_oyster
|
|
45
|
+
who_wins_with_explicit_scoping_on_class_definition_one: :fill_me_in
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# About Constants
|
|
2
|
+
|
|
3
|
+
Replace each `:fill_me_in` in `about_constants.rb` with the predicted result.
|
|
4
|
+
Each field identifies its example. Run the checks after edits to investigate the
|
|
5
|
+
next prediction. Answers include the Ruby values and exception classes shown by
|
|
6
|
+
the examples. Read the setup comments before evaluating an expression.
|
|
7
|
+
|
|
8
|
+
## Example definitions
|
|
9
|
+
|
|
10
|
+
These definitions supply the objects and methods used by the prediction examples.
|
|
11
|
+
They run in the check class `AboutConstantsTest`.
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
class Animal
|
|
15
|
+
LEGS = 4
|
|
16
|
+
def legs_in_animal
|
|
17
|
+
LEGS
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class NestedAnimal
|
|
21
|
+
def legs_in_nested_animal
|
|
22
|
+
LEGS
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Reptile < Animal
|
|
28
|
+
def legs_in_reptile
|
|
29
|
+
LEGS
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class MyAnimals
|
|
34
|
+
LEGS = 2
|
|
35
|
+
|
|
36
|
+
class Bird < Animal
|
|
37
|
+
def legs_in_bird
|
|
38
|
+
LEGS
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class MyAnimals::Oyster < Animal
|
|
44
|
+
def legs_in_oyster
|
|
45
|
+
LEGS
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
51
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Hint
|
|
2
|
+
|
|
3
|
+
Trace both lexical nesting and inheritance. A leading `::` starts at the
|
|
4
|
+
top level. Compare nested class syntax with `class Outer::Inner` syntax.
|
|
5
|
+
|
|
6
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
7
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
# Replace each :fill_me_in with the result of the described expression.
|
|
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.
|
|
16
|
+
# if true
|
|
17
|
+
# result = :true_value
|
|
18
|
+
# else
|
|
19
|
+
# result = :false_value
|
|
20
|
+
# end
|
|
21
|
+
# assert_equal __, result
|
|
22
|
+
# Predict: result
|
|
23
|
+
if_then_else_statements_one: :fill_me_in,
|
|
24
|
+
# If then statements.
|
|
25
|
+
# result = :default_value
|
|
26
|
+
# if true
|
|
27
|
+
# result = :true_value
|
|
28
|
+
# end
|
|
29
|
+
# assert_equal __, result
|
|
30
|
+
# Predict: result
|
|
31
|
+
if_then_statements_one: :fill_me_in,
|
|
32
|
+
# If statements return values.
|
|
33
|
+
# value = if true
|
|
34
|
+
# :true_value
|
|
35
|
+
# else
|
|
36
|
+
# :false_value
|
|
37
|
+
# end
|
|
38
|
+
# assert_equal __, value
|
|
39
|
+
# value = if false
|
|
40
|
+
# :true_value
|
|
41
|
+
# else
|
|
42
|
+
# :false_value
|
|
43
|
+
# end
|
|
44
|
+
# assert_equal __, value
|
|
45
|
+
# Predict: value
|
|
46
|
+
if_statements_return_values_one: :fill_me_in,
|
|
47
|
+
# Predict: value
|
|
48
|
+
if_statements_return_values_two: :fill_me_in,
|
|
49
|
+
# If statements with no else with false condition return value.
|
|
50
|
+
# value = if false
|
|
51
|
+
# :true_value
|
|
52
|
+
# end
|
|
53
|
+
# assert_equal __, value
|
|
54
|
+
# Predict: value
|
|
55
|
+
if_statements_with_no_else_with_false_condition_return_value_one: :fill_me_in,
|
|
56
|
+
# Condition operators.
|
|
57
|
+
# assert_equal __, (true ? :true_value : :false_value)
|
|
58
|
+
# assert_equal __, (false ? :true_value : :false_value)
|
|
59
|
+
# Predict: (true ? :true_value : :false_value)
|
|
60
|
+
condition_operators_one: :fill_me_in,
|
|
61
|
+
# Predict: (false ? :true_value : :false_value)
|
|
62
|
+
condition_operators_two: :fill_me_in,
|
|
63
|
+
# If statement modifiers.
|
|
64
|
+
# result = :default_value
|
|
65
|
+
# result = :true_value if true
|
|
66
|
+
# assert_equal __, result
|
|
67
|
+
# Predict: result
|
|
68
|
+
if_statement_modifiers_one: :fill_me_in,
|
|
69
|
+
# Unless statement.
|
|
70
|
+
# result = :default_value
|
|
71
|
+
# unless false # same as saying 'if !false', which evaluates as 'if true'
|
|
72
|
+
# result = :false_value
|
|
73
|
+
# end
|
|
74
|
+
# assert_equal __, result
|
|
75
|
+
# Predict: result
|
|
76
|
+
unless_statement_one: :fill_me_in,
|
|
77
|
+
# Unless statement evaluate true.
|
|
78
|
+
# result = :default_value
|
|
79
|
+
# unless true # same as saying 'if !true', which evaluates as 'if false'
|
|
80
|
+
# result = :true_value
|
|
81
|
+
# end
|
|
82
|
+
# assert_equal __, result
|
|
83
|
+
# Predict: result
|
|
84
|
+
unless_statement_evaluate_true_one: :fill_me_in,
|
|
85
|
+
# Unless statement modifier.
|
|
86
|
+
# result = :default_value
|
|
87
|
+
# result = :false_value unless false
|
|
88
|
+
# assert_equal __, result
|
|
89
|
+
# Predict: result
|
|
90
|
+
unless_statement_modifier_one: :fill_me_in,
|
|
91
|
+
# While statement.
|
|
92
|
+
# i = 1
|
|
93
|
+
# result = 1
|
|
94
|
+
# while i <= 10
|
|
95
|
+
# result = result * i
|
|
96
|
+
# i += 1
|
|
97
|
+
# end
|
|
98
|
+
# assert_equal __, result
|
|
99
|
+
# Predict: result
|
|
100
|
+
while_statement_one: :fill_me_in,
|
|
101
|
+
# Break statement.
|
|
102
|
+
# i = 1
|
|
103
|
+
# result = 1
|
|
104
|
+
# while true
|
|
105
|
+
# break unless i <= 10
|
|
106
|
+
# result = result * i
|
|
107
|
+
# i += 1
|
|
108
|
+
# end
|
|
109
|
+
# assert_equal __, result
|
|
110
|
+
# Predict: result
|
|
111
|
+
break_statement_one: :fill_me_in,
|
|
112
|
+
# Break statement returns values.
|
|
113
|
+
# i = 1
|
|
114
|
+
# result = while i <= 10
|
|
115
|
+
# break i if i % 2 == 0
|
|
116
|
+
# i += 1
|
|
117
|
+
# end
|
|
118
|
+
# assert_equal __, result
|
|
119
|
+
# Predict: result
|
|
120
|
+
break_statement_returns_values_one: :fill_me_in,
|
|
121
|
+
# Next statement.
|
|
122
|
+
# i = 0
|
|
123
|
+
# result = []
|
|
124
|
+
# while i < 10
|
|
125
|
+
# i += 1
|
|
126
|
+
# next if (i % 2) == 0
|
|
127
|
+
# result << i
|
|
128
|
+
# end
|
|
129
|
+
# assert_equal __, result
|
|
130
|
+
# Predict: result
|
|
131
|
+
next_statement_one: :fill_me_in,
|
|
132
|
+
# For statement.
|
|
133
|
+
# array = ["fish", "and", "chips"]
|
|
134
|
+
# result = []
|
|
135
|
+
# for item in array
|
|
136
|
+
# result << item.upcase
|
|
137
|
+
# end
|
|
138
|
+
# assert_equal [__, __, __], result
|
|
139
|
+
# Predict: result
|
|
140
|
+
for_statement_one: :fill_me_in,
|
|
141
|
+
# Times statement.
|
|
142
|
+
# sum = 0
|
|
143
|
+
# 10.times do
|
|
144
|
+
# sum += 1
|
|
145
|
+
# end
|
|
146
|
+
# assert_equal __, sum
|
|
147
|
+
# Predict: sum
|
|
148
|
+
times_statement_one: :fill_me_in
|
|
149
|
+
}
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# About Control Statements
|
|
2
|
+
|
|
3
|
+
Replace each `:fill_me_in` in `about_control_statements.rb` with the predicted result.
|
|
4
|
+
Each field identifies its example. Run the checks after edits to investigate the
|
|
5
|
+
next prediction. Answers include the Ruby values and exception classes shown by
|
|
6
|
+
the examples. Read the setup comments before evaluating an expression.
|
|
7
|
+
|
|
8
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
9
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Hint
|
|
2
|
+
|
|
3
|
+
Conditionals and loops return values. Watch what `break` returns, what
|
|
4
|
+
`next` skips, and whether an `if` without an `else` takes its branch.
|
|
5
|
+
|
|
6
|
+
Adapted from Ruby Koans by Jim Weirich and Joe O'Brien, licensed under
|
|
7
|
+
CC BY-NC-SA 3.0. See `THIRD_PARTY_NOTICES.md` for attribution and license terms.
|