From e8e1c0cbda117f1deb10d34a9c0b59841992b984 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Tue, 27 Jan 2026 21:03:18 +0200 Subject: [PATCH 01/17] Moviegoer and SimpleCalculator accept exceptions from both scopes The tests for these two learning exercises now check whether the expected exception has been defined inside or outside the main class. Solves issue #6772 --- exercises/concept/moviegoer/moviegoer_test.rb | 3 ++- .../concept/simple-calculator/simple_calculator_test.rb | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/exercises/concept/moviegoer/moviegoer_test.rb b/exercises/concept/moviegoer/moviegoer_test.rb index c31a3e4641..7925422b84 100644 --- a/exercises/concept/moviegoer/moviegoer_test.rb +++ b/exercises/concept/moviegoer/moviegoer_test.rb @@ -23,7 +23,8 @@ def test_members_get_free_popcorn end def test_regular_moviegoers_dont_get_free_popcorn - assert_raises NotMovieClubMemberError do + expected_exception=Moviegoer.include?(NotMovieClubMemberError)?(Moviegoer::NotMovieClubMemberError):NotMovieClubMemberError + assert_raises expected_exception do Moviegoer.new(25, member: false).claim_free_popcorn! end end diff --git a/exercises/concept/simple-calculator/simple_calculator_test.rb b/exercises/concept/simple-calculator/simple_calculator_test.rb index 1b26e42796..c8d426ecfa 100644 --- a/exercises/concept/simple-calculator/simple_calculator_test.rb +++ b/exercises/concept/simple-calculator/simple_calculator_test.rb @@ -27,14 +27,17 @@ def test_no_number_second_operand_raises_exception end def test_raises_exception_for_non_valid_operations - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '**') } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '**') } end def test_raises_exception_when_operation_is_nil - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, nil) } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, nil) } end def test_raises_exception_when_operation_is_an_empty_string - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '') } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '') } end end From fbd33a45b745acb4a2fb1e3d569e025321331c1e Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Tue, 27 Jan 2026 21:03:18 +0200 Subject: [PATCH 02/17] Moviegoer and SimpleCalculator accept exceptions from both scopes The tests for these two learning exercises now check whether the expected exception has been defined inside or outside the main class. Solves issue #6772 --- exercises/concept/moviegoer/moviegoer_test.rb | 3 ++- .../concept/simple-calculator/simple_calculator_test.rb | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/exercises/concept/moviegoer/moviegoer_test.rb b/exercises/concept/moviegoer/moviegoer_test.rb index c31a3e4641..7925422b84 100644 --- a/exercises/concept/moviegoer/moviegoer_test.rb +++ b/exercises/concept/moviegoer/moviegoer_test.rb @@ -23,7 +23,8 @@ def test_members_get_free_popcorn end def test_regular_moviegoers_dont_get_free_popcorn - assert_raises NotMovieClubMemberError do + expected_exception=Moviegoer.include?(NotMovieClubMemberError)?(Moviegoer::NotMovieClubMemberError):NotMovieClubMemberError + assert_raises expected_exception do Moviegoer.new(25, member: false).claim_free_popcorn! end end diff --git a/exercises/concept/simple-calculator/simple_calculator_test.rb b/exercises/concept/simple-calculator/simple_calculator_test.rb index 1b26e42796..c8d426ecfa 100644 --- a/exercises/concept/simple-calculator/simple_calculator_test.rb +++ b/exercises/concept/simple-calculator/simple_calculator_test.rb @@ -27,14 +27,17 @@ def test_no_number_second_operand_raises_exception end def test_raises_exception_for_non_valid_operations - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '**') } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '**') } end def test_raises_exception_when_operation_is_nil - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, nil) } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, nil) } end def test_raises_exception_when_operation_is_an_empty_string - assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '') } + expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '') } end end From 3ed741b3db62124edff8baef6d1752cd009853e9 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Sun, 15 Feb 2026 19:25:37 +0200 Subject: [PATCH 03/17] whitespace fixes --- exercises/concept/moviegoer/moviegoer_test.rb | 2 +- .../concept/simple-calculator/simple_calculator_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/concept/moviegoer/moviegoer_test.rb b/exercises/concept/moviegoer/moviegoer_test.rb index 7925422b84..892ffcc615 100644 --- a/exercises/concept/moviegoer/moviegoer_test.rb +++ b/exercises/concept/moviegoer/moviegoer_test.rb @@ -23,7 +23,7 @@ def test_members_get_free_popcorn end def test_regular_moviegoers_dont_get_free_popcorn - expected_exception=Moviegoer.include?(NotMovieClubMemberError)?(Moviegoer::NotMovieClubMemberError):NotMovieClubMemberError + expected_exception = Moviegoer.include?(NotMovieClubMemberError) ? Moviegoer::NotMovieClubMemberError : NotMovieClubMemberError assert_raises expected_exception do Moviegoer.new(25, member: false).claim_free_popcorn! end diff --git a/exercises/concept/simple-calculator/simple_calculator_test.rb b/exercises/concept/simple-calculator/simple_calculator_test.rb index c8d426ecfa..7b1c8b8023 100644 --- a/exercises/concept/simple-calculator/simple_calculator_test.rb +++ b/exercises/concept/simple-calculator/simple_calculator_test.rb @@ -27,17 +27,17 @@ def test_no_number_second_operand_raises_exception end def test_raises_exception_for_non_valid_operations - expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '**') } end def test_raises_exception_when_operation_is_nil - expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, nil) } end def test_raises_exception_when_operation_is_an_empty_string - expected_exception=SimpleCalculator.include?(UnsupportedOperation)?(SimpleCalculator::UnsupportedOperation):UnsupportedOperation + expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '') } end end From cead53fbccf7a4f1b44ecd228b234c1b750a7e7c Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 14:44:07 +0300 Subject: [PATCH 04/17] Files for last will exercise. --- exercises/concept/last-will/HELP.md | 54 ++++++++++++ exercises/concept/last-will/HINTS.md | 20 +++++ exercises/concept/last-will/README.md | 86 +++++++++++++++++++ exercises/concept/last-will/last_will.rb | 57 ++++++++++++ exercises/concept/last-will/last_will_test.rb | 41 +++++++++ 5 files changed, 258 insertions(+) create mode 100755 exercises/concept/last-will/HELP.md create mode 100755 exercises/concept/last-will/HINTS.md create mode 100755 exercises/concept/last-will/README.md create mode 100755 exercises/concept/last-will/last_will.rb create mode 100755 exercises/concept/last-will/last_will_test.rb diff --git a/exercises/concept/last-will/HELP.md b/exercises/concept/last-will/HELP.md new file mode 100755 index 0000000000..a00906aa82 --- /dev/null +++ b/exercises/concept/last-will/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + +``` +gem install minitest +``` + + +Run the tests from the exercise directory using the following command: + +``` +ruby _test.rb +``` + +Please replace `` with your exercise name in snake_case. + +## Color output + +You can `require 'minitest/pride'` or run the following command to get colored output: + +``` +ruby -r minitest/pride _test.rb +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit last_will.rb` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) +- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Ruby Documentation](http://ruby-doc.org/) +- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) +- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file diff --git a/exercises/concept/last-will/HINTS.md b/exercises/concept/last-will/HINTS.md new file mode 100755 index 0000000000..c725e7ccab --- /dev/null +++ b/exercises/concept/last-will/HINTS.md @@ -0,0 +1,20 @@ +# Hints + +## General + +- Do not change the code in the families' namespaces. +- Do not copy the values into your code, call the functions. + +## 1. Take your seat in front of the families and lay out your papers + +- The namespace has to be called `EstateExecutor` for the tests to work. + +## 2. Find the secret account number + +Each `bank_number_part` has to be called with the `secret_modifier` from the parameter list. + +## 3. Last step: Enter the secret code + +- You can call functions from nested namespaces like this `OuterNamespace::InnerNamespace::my_function`. + +- Take care to add the blue and the red fragments separately before multiplicating both parts. \ No newline at end of file diff --git a/exercises/concept/last-will/README.md b/exercises/concept/last-will/README.md new file mode 100755 index 0000000000..dcbb2b3dc1 --- /dev/null +++ b/exercises/concept/last-will/README.md @@ -0,0 +1,86 @@ +# Last Will + +Welcome to Last Will on Exercism's Ruby Track. +If you need help running the tests or submitting your code, check out `HELP.md`. +If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :) + +## Introduction + +## Namespaces + +An important method for code organization is the use of namespaces. +Classes and modules can be namespaces. +Two methods might have a naming collision, which can be resolved by putting them in different namespaces. +Namespaces can be nested, which might help to structure big code bases. +Access to the namespaces is done via the scope-resolution operator `::`. + +The example below shows the use of two different `foo` methods. +They are used together by prefixing their respective namespaces. + +```ruby +class MyNs + def self.foo + 44 + end + class MyInnerNs + def self.baz + 90 + end + end +end +class MyOtherNs + def self.foo + -2 + end +end + +p MyNs::foo + MyOtherNs::foo * MyNs::MyInnerNs::baz +``` + +## Instructions + +You work for a prestigious law firm that is specialized in handling unique testament requests. + +In this exercise, you are going to open a mysterious vault. +You are the executor of the estate and will assemble the long-kept secret codes of three families to get an account number and the matching code. + +To prevent any family from opening the vault alone, it can only be opened by combining their knowledge with a secret modifier that you know from the last will. + +You have three tasks, all related to helping the families to open the vault. + +## 1. Take your seat in front of the families and lay out your papers + +Define a namespace called `EstateExecutor`. +The code from the next tasks should be defined in the body of the `EstateExecutor` namespace. + +```ruby +class SomeName + # The space between the class/module name + # and the `end` keyword + # is called body of the namespace. +end +``` + +## 2. Find the secret account number + +This is your big moment. +Only you have the secret modifier key to reveal the secret account number. + +Define the `assemble_account_number(secret_modifier)` method that takes the `Integer` secret modifier as an argument and returns the `Integer` assembled account number. + +To get the correct number, you have to sum up the `bank_number_part` from each of the three families. + +## 3. Last step: Enter the secret code + +The instructions in the testament ask you to add all the blue and then all the red fragments. +The resulting code is obtained by multiplying both sums. + +Define the `assemble_code` method that returns the resulting code by combining the fragments from the three families to a single `Integer` result. +The method does not have any arguments and relies solely on the information in the relevant namespaces from the families. + +## Source + +### Created by + +- @vaeng (original C++ exercise) +- @vaiapatta1985 (transcription to Ruby) \ No newline at end of file diff --git a/exercises/concept/last-will/last_will.rb b/exercises/concept/last-will/last_will.rb new file mode 100755 index 0000000000..d6fd817e54 --- /dev/null +++ b/exercises/concept/last-will/last_will.rb @@ -0,0 +1,57 @@ +# Enter your code below the lines of the families' information + +# Secret knowledge of the Zhang family: +class Zhang + def self.bank_number_part(secret_modifier) + zhang_part = 8541 + (zhang_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 512 + end + end + class Blue + def self.code_fragment + 677 + end + end +end + +# Secret knowledge of the Khan family: +class Khan + def self.bank_number_part(secret_modifier) + khan_part = 4142 + (khan_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 148 + end + end + class Blue + def self.code_fragment + 875 + end + end +end + +# Secret knowledge of the Garcia family: +class Garcia + def self.bank_number_part(secret_modifier) + garcia_part = 4023 + (garcia_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 118 + end + end + class Blue + def self.code_fragment + 923 + end + end +end + +# Enter your code below diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb new file mode 100755 index 0000000000..716f391c6e --- /dev/null +++ b/exercises/concept/last-will/last_will_test.rb @@ -0,0 +1,41 @@ +require 'minitest/autorun' +require_relative 'last_will' + +class LastWillTest < Minitest::Test + def test_family_secrets_unaltered + #skip + assert_equal Zhang::bank_number_part(1), 8541 + assert_equal Zhang::bank_number_part(3), 8541 * 3 % 10000 + assert_equal Khan::bank_number_part(1), 4142 + assert_equal Khan::bank_number_part(3), 4142 * 3 % 10000 + assert_equal Garcia::bank_number_part(1), 4023 + assert_equal Garcia::bank_number_part(3), 4023 * 3 % 10000 + assert_equal Zhang::Red::code_fragment, 512 + assert_equal Khan::Red::code_fragment, 148 + assert_equal Garcia::Red::code_fragment, 118 + assert_equal Zhang::Blue::code_fragment, 677 + assert_equal Khan::Blue::code_fragment, 875 + assert_equal Garcia::Blue::code_fragment, 923 + end + + def test_account_number_assembly_method_in_correct_namespace + #skip + assert EstateExecutor.include?(assemble_account_number) + end + + def test_account_number_assembly_method_works + #skip + assert_equal EstateExecutor::assemble_account_number(1), 16706 + assert_equal EstateExecutor::assemble_account_number(23), 14238 + end + + def test_code_fragment_number_assembly_method_in_correct_namespace + #skip + assert EstateExecutor.include?(assemble_code) + end + + def test_code_fragments_fit + #skip + assert_equal EstateExecutor::assemble_code, 1925550 + end +end From f26fae3d1fb151b74d6acc7616f18fa2677f6393 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 16:10:31 +0300 Subject: [PATCH 05/17] More files for the last will exercise. --- concepts/namespaces/.meta/config.json | 5 ++ concepts/namespaces/about.md | 32 ++++++++++ concepts/namespaces/introduction.md | 32 ++++++++++ concepts/namespaces/links.json | 1 + .../last-will/{HINTS.md => .docs/hints.md} | 0 .../{README.md => .docs/instructions.md} | 53 +++------------- .../concept/last-will/.docs/introduction.md | 32 ++++++++++ exercises/concept/last-will/.meta/config.json | 18 ++++++ exercises/concept/last-will/.meta/design.md | 40 ++++++++++++ exercises/concept/last-will/.meta/exemplar.rb | 63 +++++++++++++++++++ exercises/concept/last-will/HELP.md | 54 ---------------- 11 files changed, 230 insertions(+), 100 deletions(-) create mode 100644 concepts/namespaces/.meta/config.json create mode 100755 concepts/namespaces/about.md create mode 100755 concepts/namespaces/introduction.md create mode 100644 concepts/namespaces/links.json rename exercises/concept/last-will/{HINTS.md => .docs/hints.md} (100%) rename exercises/concept/last-will/{README.md => .docs/instructions.md} (57%) mode change 100755 => 100644 create mode 100755 exercises/concept/last-will/.docs/introduction.md create mode 100644 exercises/concept/last-will/.meta/config.json create mode 100644 exercises/concept/last-will/.meta/design.md create mode 100644 exercises/concept/last-will/.meta/exemplar.rb delete mode 100755 exercises/concept/last-will/HELP.md diff --git a/concepts/namespaces/.meta/config.json b/concepts/namespaces/.meta/config.json new file mode 100644 index 0000000000..b87436ef0c --- /dev/null +++ b/concepts/namespaces/.meta/config.json @@ -0,0 +1,5 @@ +{ + "blurb": "Classes and modules can be namespaces. Namespaces can be nested, which might help to structure big code bases. Access to the namespaces is done via the scope-resolution operator.", + "authors": ["vaeng","vaiapatta1985"], + "contributors": [] +} diff --git a/concepts/namespaces/about.md b/concepts/namespaces/about.md new file mode 100755 index 0000000000..7fe0414a01 --- /dev/null +++ b/concepts/namespaces/about.md @@ -0,0 +1,32 @@ +# Introduction + +# Namespaces + +An important method for code organization is the use of namespaces. +Classes and modules can be namespaces. +Two methods might have a naming collision, which can be resolved by putting them in different namespaces. +Namespaces can be nested, which might help to structure big code bases. +Access to the namespaces is done via the scope-resolution operator `::`. + +The example below shows the use of two different `foo` methods. +They are used together by prefixing their respective namespaces. + +```ruby +class MyNamespace + def self.foo + 44 + end + class MyInnerNamespace + def self.baz + 90 + end + end +end +class MyOtherNamespace + def self.foo + -2 + end +end + +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +``` diff --git a/concepts/namespaces/introduction.md b/concepts/namespaces/introduction.md new file mode 100755 index 0000000000..7fe0414a01 --- /dev/null +++ b/concepts/namespaces/introduction.md @@ -0,0 +1,32 @@ +# Introduction + +# Namespaces + +An important method for code organization is the use of namespaces. +Classes and modules can be namespaces. +Two methods might have a naming collision, which can be resolved by putting them in different namespaces. +Namespaces can be nested, which might help to structure big code bases. +Access to the namespaces is done via the scope-resolution operator `::`. + +The example below shows the use of two different `foo` methods. +They are used together by prefixing their respective namespaces. + +```ruby +class MyNamespace + def self.foo + 44 + end + class MyInnerNamespace + def self.baz + 90 + end + end +end +class MyOtherNamespace + def self.foo + -2 + end +end + +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +``` diff --git a/concepts/namespaces/links.json b/concepts/namespaces/links.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/concepts/namespaces/links.json @@ -0,0 +1 @@ +[] diff --git a/exercises/concept/last-will/HINTS.md b/exercises/concept/last-will/.docs/hints.md similarity index 100% rename from exercises/concept/last-will/HINTS.md rename to exercises/concept/last-will/.docs/hints.md diff --git a/exercises/concept/last-will/README.md b/exercises/concept/last-will/.docs/instructions.md old mode 100755 new mode 100644 similarity index 57% rename from exercises/concept/last-will/README.md rename to exercises/concept/last-will/.docs/instructions.md index dcbb2b3dc1..f2893573f5 --- a/exercises/concept/last-will/README.md +++ b/exercises/concept/last-will/.docs/instructions.md @@ -1,43 +1,4 @@ -# Last Will - -Welcome to Last Will on Exercism's Ruby Track. -If you need help running the tests or submitting your code, check out `HELP.md`. -If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :) - -## Introduction - -## Namespaces - -An important method for code organization is the use of namespaces. -Classes and modules can be namespaces. -Two methods might have a naming collision, which can be resolved by putting them in different namespaces. -Namespaces can be nested, which might help to structure big code bases. -Access to the namespaces is done via the scope-resolution operator `::`. - -The example below shows the use of two different `foo` methods. -They are used together by prefixing their respective namespaces. - -```ruby -class MyNs - def self.foo - 44 - end - class MyInnerNs - def self.baz - 90 - end - end -end -class MyOtherNs - def self.foo - -2 - end -end - -p MyNs::foo + MyOtherNs::foo * MyNs::MyInnerNs::baz -``` - -## Instructions +# Instructions You work for a prestigious law firm that is specialized in handling unique testament requests. @@ -48,7 +9,7 @@ To prevent any family from opening the vault alone, it can only be opened by com You have three tasks, all related to helping the families to open the vault. -## 1. Take your seat in front of the families and lay out your papers +# 1. Take your seat in front of the families and lay out your papers Define a namespace called `EstateExecutor`. The code from the next tasks should be defined in the body of the `EstateExecutor` namespace. @@ -61,7 +22,7 @@ class SomeName end ``` -## 2. Find the secret account number +# 2. Find the secret account number This is your big moment. Only you have the secret modifier key to reveal the secret account number. @@ -70,7 +31,7 @@ Define the `assemble_account_number(secret_modifier)` method that takes the `Int To get the correct number, you have to sum up the `bank_number_part` from each of the three families. -## 3. Last step: Enter the secret code +# 3. Last step: Enter the secret code The instructions in the testament ask you to add all the blue and then all the red fragments. The resulting code is obtained by multiplying both sums. @@ -78,9 +39,9 @@ The resulting code is obtained by multiplying both sums. Define the `assemble_code` method that returns the resulting code by combining the fragments from the three families to a single `Integer` result. The method does not have any arguments and relies solely on the information in the relevant namespaces from the families. -## Source +# Source -### Created by +## Created by - @vaeng (original C++ exercise) -- @vaiapatta1985 (transcription to Ruby) \ No newline at end of file +- @vaiapatta1985 (transcription to Ruby) diff --git a/exercises/concept/last-will/.docs/introduction.md b/exercises/concept/last-will/.docs/introduction.md new file mode 100755 index 0000000000..7fe0414a01 --- /dev/null +++ b/exercises/concept/last-will/.docs/introduction.md @@ -0,0 +1,32 @@ +# Introduction + +# Namespaces + +An important method for code organization is the use of namespaces. +Classes and modules can be namespaces. +Two methods might have a naming collision, which can be resolved by putting them in different namespaces. +Namespaces can be nested, which might help to structure big code bases. +Access to the namespaces is done via the scope-resolution operator `::`. + +The example below shows the use of two different `foo` methods. +They are used together by prefixing their respective namespaces. + +```ruby +class MyNamespace + def self.foo + 44 + end + class MyInnerNamespace + def self.baz + 90 + end + end +end +class MyOtherNamespace + def self.foo + -2 + end +end + +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +``` diff --git a/exercises/concept/last-will/.meta/config.json b/exercises/concept/last-will/.meta/config.json new file mode 100644 index 0000000000..8203fd0559 --- /dev/null +++ b/exercises/concept/last-will/.meta/config.json @@ -0,0 +1,18 @@ +{ + "authors": [ + "vaeng", + "vaiapatta1985" + ], + "files": { + "solution": [ + "last_will.rb" + ], + "test": [ + "last_will_test.rb" + ], + "exemplar": [ + ".meta/exemplar.rb" + ] + }, + "blurb": "Classes and modules can be namespaces. Namespaces can be nested, which might help to structure big code bases. Access to the namespaces is done via the scope-resolution operator." +} diff --git a/exercises/concept/last-will/.meta/design.md b/exercises/concept/last-will/.meta/design.md new file mode 100644 index 0000000000..0f0b9fdcc7 --- /dev/null +++ b/exercises/concept/last-will/.meta/design.md @@ -0,0 +1,40 @@ +# Design + +## Goal + +The goal of this exercise is to teach the student how to use namespaces in Ruby. + +## Learning objectives + +- Know how to call a method defined in a namespace. +- Know how to organize methods in namespaces. + +## Out of scope + +- Memory and performance characteristics. +- Method overloads. +- Lambdas. +- Optional parameters. +- Visibility. + +## Concepts + +The Concepts this exercise unlocks are: + +- `namespaces`: know how to call a method defined in a namespace; know how to organize methods in namespaces. + +## Prerequisites + +- `basics` +- `modules` + +## Representer + +This exercise does not require any specific representation logic to be added to the [representer][representer]. + +## Analyzer + +This exercise does not require any specific logic to be added to the [analyzer][analyzer]. + +[analyzer]: https://github.com/exercism/ruby-analyzer +[representer]: https://github.com/exercism/ruby-representer diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb new file mode 100644 index 0000000000..d03caab4af --- /dev/null +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -0,0 +1,63 @@ +# Secret knowledge of the Zhang family: +class Zhang + def self.bank_number_part(secret_modifier) + zhang_part = 8541 + (zhang_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 512 + end + end + class Blue + def self.code_fragment + 677 + end + end +end + +# Secret knowledge of the Khan family: +class Khan + def self.bank_number_part(secret_modifier) + khan_part = 4142 + (khan_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 148 + end + end + class Blue + def self.code_fragment + 875 + end + end +end + +# Secret knowledge of the Garcia family: +class Garcia + def self.bank_number_part(secret_modifier) + garcia_part = 4023 + (garcia_part * secret_modifier) % 10000 + end + class Red + def self.code_fragment + 118 + end + end + class Blue + def self.code_fragment + 923 + end + end +end + +class EstateExecutor + def self.assemble_account_number(secret_modifier) + Zhang::bank_number_part(secret_modifier) + Khang::bank_number_part(secret_modifier) + Garcia::bank_number_part(secret_modifier) + end + + def self.assemble_code + Zhang::Red::code_fragment + Khang::Red::code_fragment + Garcia::Red::code_fragment + Zhang::Blue::code_fragment + Khang::Blue::code_fragment + Garcia::Blue::code_fragment + end +end diff --git a/exercises/concept/last-will/HELP.md b/exercises/concept/last-will/HELP.md deleted file mode 100755 index a00906aa82..0000000000 --- a/exercises/concept/last-will/HELP.md +++ /dev/null @@ -1,54 +0,0 @@ -# Help - -## Running the tests - -For running the tests provided, you will need the Minitest gem. Open a -terminal window and run the following command to install minitest: - -``` -gem install minitest -``` - - -Run the tests from the exercise directory using the following command: - -``` -ruby _test.rb -``` - -Please replace `` with your exercise name in snake_case. - -## Color output - -You can `require 'minitest/pride'` or run the following command to get colored output: - -``` -ruby -r minitest/pride _test.rb -``` - -## Submitting your solution - -You can submit your solution using the `exercism submit last_will.rb` command. -This command will upload your solution to the Exercism website and print the solution page's URL. - -It's possible to submit an incomplete solution which allows you to: - -- See how others have completed the exercise -- Request help from a mentor - -## Need to get help? - -If you'd like help solving the exercise, check the following pages: - -- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) -- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) -- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) -- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) - -Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. - -To get help if you're having trouble, you can use one of the following resources: - -- [Ruby Documentation](http://ruby-doc.org/) -- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) -- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file From 8f8d99278306c57f2f8fc8116b73d92fc535d362 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 19:54:11 +0300 Subject: [PATCH 06/17] Corrections. --- concepts/namespaces/about.md | 26 ++++++++++++++++++- concepts/namespaces/introduction.md | 26 ++++++++++++++++++- .../concept/last-will/.docs/introduction.md | 26 ++++++++++++++++++- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/concepts/namespaces/about.md b/concepts/namespaces/about.md index 7fe0414a01..a5942b54d1 100755 --- a/concepts/namespaces/about.md +++ b/concepts/namespaces/about.md @@ -28,5 +28,29 @@ class MyOtherNamespace end end -p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 +``` + +Note that namespaces are interpreted based on where the executing code is. +To refer to something in the *root* namespace, (ie outside all defined namespaces), start with `::`. + +For example: + +```ruby +class Example + def self.example + 5 + end +end +class MyNamespace + class Example + def self.example + 10 + end + end + def self.call_example + p Example::example # => 10 + p ::Example::example # => 5 + end +end ``` diff --git a/concepts/namespaces/introduction.md b/concepts/namespaces/introduction.md index 7fe0414a01..a5942b54d1 100755 --- a/concepts/namespaces/introduction.md +++ b/concepts/namespaces/introduction.md @@ -28,5 +28,29 @@ class MyOtherNamespace end end -p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 +``` + +Note that namespaces are interpreted based on where the executing code is. +To refer to something in the *root* namespace, (ie outside all defined namespaces), start with `::`. + +For example: + +```ruby +class Example + def self.example + 5 + end +end +class MyNamespace + class Example + def self.example + 10 + end + end + def self.call_example + p Example::example # => 10 + p ::Example::example # => 5 + end +end ``` diff --git a/exercises/concept/last-will/.docs/introduction.md b/exercises/concept/last-will/.docs/introduction.md index 7fe0414a01..a5942b54d1 100755 --- a/exercises/concept/last-will/.docs/introduction.md +++ b/exercises/concept/last-will/.docs/introduction.md @@ -28,5 +28,29 @@ class MyOtherNamespace end end -p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz +p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 +``` + +Note that namespaces are interpreted based on where the executing code is. +To refer to something in the *root* namespace, (ie outside all defined namespaces), start with `::`. + +For example: + +```ruby +class Example + def self.example + 5 + end +end +class MyNamespace + class Example + def self.example + 10 + end + end + def self.call_example + p Example::example # => 10 + p ::Example::example # => 5 + end +end ``` From 9d1762daee633cf8adfc8d3e41a250667206c3d7 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 19:55:41 +0300 Subject: [PATCH 07/17] Corrections. --- exercises/concept/last-will/.meta/exemplar.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb index d03caab4af..0f274fedec 100644 --- a/exercises/concept/last-will/.meta/exemplar.rb +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -54,10 +54,10 @@ def self.code_fragment class EstateExecutor def self.assemble_account_number(secret_modifier) - Zhang::bank_number_part(secret_modifier) + Khang::bank_number_part(secret_modifier) + Garcia::bank_number_part(secret_modifier) + ::Zhang::bank_number_part(secret_modifier) + ::Khang::bank_number_part(secret_modifier) + ::Garcia::bank_number_part(secret_modifier) end def self.assemble_code - Zhang::Red::code_fragment + Khang::Red::code_fragment + Garcia::Red::code_fragment + Zhang::Blue::code_fragment + Khang::Blue::code_fragment + Garcia::Blue::code_fragment + ::Zhang::Red::code_fragment + ::Khang::Red::code_fragment + ::Garcia::Red::code_fragment + ::Zhang::Blue::code_fragment + ::Khang::Blue::code_fragment + ::Garcia::Blue::code_fragment end end From 2758b8c8ecd6e0940ae4c701784cb5d42e3c5ede Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 22:41:34 +0300 Subject: [PATCH 08/17] Corrections. --- exercises/concept/last-will/last_will_test.rb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb index 716f391c6e..6d0141780a 100755 --- a/exercises/concept/last-will/last_will_test.rb +++ b/exercises/concept/last-will/last_will_test.rb @@ -4,38 +4,38 @@ class LastWillTest < Minitest::Test def test_family_secrets_unaltered #skip - assert_equal Zhang::bank_number_part(1), 8541 - assert_equal Zhang::bank_number_part(3), 8541 * 3 % 10000 - assert_equal Khan::bank_number_part(1), 4142 - assert_equal Khan::bank_number_part(3), 4142 * 3 % 10000 - assert_equal Garcia::bank_number_part(1), 4023 - assert_equal Garcia::bank_number_part(3), 4023 * 3 % 10000 - assert_equal Zhang::Red::code_fragment, 512 - assert_equal Khan::Red::code_fragment, 148 - assert_equal Garcia::Red::code_fragment, 118 - assert_equal Zhang::Blue::code_fragment, 677 - assert_equal Khan::Blue::code_fragment, 875 - assert_equal Garcia::Blue::code_fragment, 923 + assert_equal ::Zhang::bank_number_part(1), 8541 + assert_equal ::Zhang::bank_number_part(3), 8541 * 3 % 10000 + assert_equal ::Khan::bank_number_part(1), 4142 + assert_equal ::Khan::bank_number_part(3), 4142 * 3 % 10000 + assert_equal ::Garcia::bank_number_part(1), 4023 + assert_equal ::Garcia::bank_number_part(3), 4023 * 3 % 10000 + assert_equal ::Zhang::Red::code_fragment, 512 + assert_equal ::Khan::Red::code_fragment, 148 + assert_equal ::Garcia::Red::code_fragment, 118 + assert_equal ::Zhang::Blue::code_fragment, 677 + assert_equal ::Khan::Blue::code_fragment, 875 + assert_equal ::Garcia::Blue::code_fragment, 923 end def test_account_number_assembly_method_in_correct_namespace #skip - assert EstateExecutor.include?(assemble_account_number) + assert ::EstateExecutor.include?(assemble_account_number) end def test_account_number_assembly_method_works #skip - assert_equal EstateExecutor::assemble_account_number(1), 16706 - assert_equal EstateExecutor::assemble_account_number(23), 14238 + assert_equal ::EstateExecutor::assemble_account_number(1), 16706 + assert_equal ::EstateExecutor::assemble_account_number(23), 14238 end def test_code_fragment_number_assembly_method_in_correct_namespace #skip - assert EstateExecutor.include?(assemble_code) + assert ::EstateExecutor.include?(assemble_code) end def test_code_fragments_fit #skip - assert_equal EstateExecutor::assemble_code, 1925550 + assert_equal ::EstateExecutor::assemble_code, 1925550 end end From 25703e6ba0e702636a14b82ede3d85f161877ebe Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 22:45:25 +0300 Subject: [PATCH 09/17] Corrections. --- exercises/concept/last-will/last_will_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb index 6d0141780a..663b845b02 100755 --- a/exercises/concept/last-will/last_will_test.rb +++ b/exercises/concept/last-will/last_will_test.rb @@ -6,15 +6,15 @@ def test_family_secrets_unaltered #skip assert_equal ::Zhang::bank_number_part(1), 8541 assert_equal ::Zhang::bank_number_part(3), 8541 * 3 % 10000 - assert_equal ::Khan::bank_number_part(1), 4142 - assert_equal ::Khan::bank_number_part(3), 4142 * 3 % 10000 + assert_equal ::Khang::bank_number_part(1), 4142 + assert_equal ::Khang::bank_number_part(3), 4142 * 3 % 10000 assert_equal ::Garcia::bank_number_part(1), 4023 assert_equal ::Garcia::bank_number_part(3), 4023 * 3 % 10000 assert_equal ::Zhang::Red::code_fragment, 512 - assert_equal ::Khan::Red::code_fragment, 148 + assert_equal ::Khang::Red::code_fragment, 148 assert_equal ::Garcia::Red::code_fragment, 118 assert_equal ::Zhang::Blue::code_fragment, 677 - assert_equal ::Khan::Blue::code_fragment, 875 + assert_equal ::Khang::Blue::code_fragment, 875 assert_equal ::Garcia::Blue::code_fragment, 923 end From 49551886df7a6af99497afa60887d20c573ceff2 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 22:48:42 +0300 Subject: [PATCH 10/17] Corrections. --- exercises/concept/last-will/.meta/exemplar.rb | 4 ++-- exercises/concept/last-will/last_will_test.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb index 0f274fedec..279d857567 100644 --- a/exercises/concept/last-will/.meta/exemplar.rb +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -54,10 +54,10 @@ def self.code_fragment class EstateExecutor def self.assemble_account_number(secret_modifier) - ::Zhang::bank_number_part(secret_modifier) + ::Khang::bank_number_part(secret_modifier) + ::Garcia::bank_number_part(secret_modifier) + ::Zhang::bank_number_part(secret_modifier) + ::Khan::bank_number_part(secret_modifier) + ::Garcia::bank_number_part(secret_modifier) end def self.assemble_code - ::Zhang::Red::code_fragment + ::Khang::Red::code_fragment + ::Garcia::Red::code_fragment + ::Zhang::Blue::code_fragment + ::Khang::Blue::code_fragment + ::Garcia::Blue::code_fragment + ::Zhang::Red::code_fragment + ::Khan::Red::code_fragment + ::Garcia::Red::code_fragment + ::Zhang::Blue::code_fragment + ::Khan::Blue::code_fragment + ::Garcia::Blue::code_fragment end end diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb index 663b845b02..6d0141780a 100755 --- a/exercises/concept/last-will/last_will_test.rb +++ b/exercises/concept/last-will/last_will_test.rb @@ -6,15 +6,15 @@ def test_family_secrets_unaltered #skip assert_equal ::Zhang::bank_number_part(1), 8541 assert_equal ::Zhang::bank_number_part(3), 8541 * 3 % 10000 - assert_equal ::Khang::bank_number_part(1), 4142 - assert_equal ::Khang::bank_number_part(3), 4142 * 3 % 10000 + assert_equal ::Khan::bank_number_part(1), 4142 + assert_equal ::Khan::bank_number_part(3), 4142 * 3 % 10000 assert_equal ::Garcia::bank_number_part(1), 4023 assert_equal ::Garcia::bank_number_part(3), 4023 * 3 % 10000 assert_equal ::Zhang::Red::code_fragment, 512 - assert_equal ::Khang::Red::code_fragment, 148 + assert_equal ::Khan::Red::code_fragment, 148 assert_equal ::Garcia::Red::code_fragment, 118 assert_equal ::Zhang::Blue::code_fragment, 677 - assert_equal ::Khang::Blue::code_fragment, 875 + assert_equal ::Khan::Blue::code_fragment, 875 assert_equal ::Garcia::Blue::code_fragment, 923 end From 3d9a791c747bdb227bc85f988e7c6dc6eee717f4 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 22:54:52 +0300 Subject: [PATCH 11/17] Corrections. --- exercises/concept/last-will/.meta/exemplar.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb index 279d857567..5434b88b6b 100644 --- a/exercises/concept/last-will/.meta/exemplar.rb +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -58,6 +58,6 @@ def self.assemble_account_number(secret_modifier) end def self.assemble_code - ::Zhang::Red::code_fragment + ::Khan::Red::code_fragment + ::Garcia::Red::code_fragment + ::Zhang::Blue::code_fragment + ::Khan::Blue::code_fragment + ::Garcia::Blue::code_fragment + (::Zhang::Red::code_fragment + ::Khan::Red::code_fragment + ::Garcia::Red::code_fragment) * (::Zhang::Blue::code_fragment + ::Khan::Blue::code_fragment + ::Garcia::Blue::code_fragment) end end From 191299199683c66cef48a65367cd0bc388c8821f Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Wed, 13 May 2026 23:04:17 +0300 Subject: [PATCH 12/17] Corrections. --- exercises/concept/last-will/last_will_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb index 6d0141780a..93ffa9b5b8 100755 --- a/exercises/concept/last-will/last_will_test.rb +++ b/exercises/concept/last-will/last_will_test.rb @@ -20,7 +20,7 @@ def test_family_secrets_unaltered def test_account_number_assembly_method_in_correct_namespace #skip - assert ::EstateExecutor.include?(assemble_account_number) + assert ::EstateExecutor.respond_to?(:assemble_account_number) end def test_account_number_assembly_method_works @@ -31,7 +31,7 @@ def test_account_number_assembly_method_works def test_code_fragment_number_assembly_method_in_correct_namespace #skip - assert ::EstateExecutor.include?(assemble_code) + assert ::EstateExecutor.respond_to?(:assemble_code) end def test_code_fragments_fit From 3f781b06b8c8947a750534ce25c893ed9c773959 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Thu, 14 May 2026 06:32:33 +0300 Subject: [PATCH 13/17] Corrections. --- exercises/concept/moviegoer/moviegoer_test.rb | 3 +-- .../concept/simple-calculator/simple_calculator_test.rb | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/exercises/concept/moviegoer/moviegoer_test.rb b/exercises/concept/moviegoer/moviegoer_test.rb index 892ffcc615..c31a3e4641 100644 --- a/exercises/concept/moviegoer/moviegoer_test.rb +++ b/exercises/concept/moviegoer/moviegoer_test.rb @@ -23,8 +23,7 @@ def test_members_get_free_popcorn end def test_regular_moviegoers_dont_get_free_popcorn - expected_exception = Moviegoer.include?(NotMovieClubMemberError) ? Moviegoer::NotMovieClubMemberError : NotMovieClubMemberError - assert_raises expected_exception do + assert_raises NotMovieClubMemberError do Moviegoer.new(25, member: false).claim_free_popcorn! end end diff --git a/exercises/concept/simple-calculator/simple_calculator_test.rb b/exercises/concept/simple-calculator/simple_calculator_test.rb index 7b1c8b8023..1b26e42796 100644 --- a/exercises/concept/simple-calculator/simple_calculator_test.rb +++ b/exercises/concept/simple-calculator/simple_calculator_test.rb @@ -27,17 +27,14 @@ def test_no_number_second_operand_raises_exception end def test_raises_exception_for_non_valid_operations - expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation - assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '**') } + assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '**') } end def test_raises_exception_when_operation_is_nil - expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation - assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, nil) } + assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, nil) } end def test_raises_exception_when_operation_is_an_empty_string - expected_exception = SimpleCalculator.include?(UnsupportedOperation) ? SimpleCalculator::UnsupportedOperation : UnsupportedOperation - assert_raises(expected_exception) { SimpleCalculator.calculate(1, 2, '') } + assert_raises(SimpleCalculator::UnsupportedOperation) { SimpleCalculator.calculate(1, 2, '') } end end From a905daa4c36df5e9bfe8238754b6efe371a40b79 Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Thu, 14 May 2026 06:38:48 +0300 Subject: [PATCH 14/17] Corrections. --- concepts/namespaces/about.md | 25 +++++++++++-------- concepts/namespaces/introduction.md | 25 +++++++++++-------- .../concept/last-will/.docs/introduction.md | 25 +++++++++++-------- exercises/concept/last-will/.meta/exemplar.rb | 6 +++++ exercises/concept/last-will/last_will.rb | 6 +++++ 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/concepts/namespaces/about.md b/concepts/namespaces/about.md index a5942b54d1..4fc10f8c8b 100755 --- a/concepts/namespaces/about.md +++ b/concepts/namespaces/about.md @@ -13,19 +13,21 @@ They are used together by prefixing their respective namespaces. ```ruby class MyNamespace - def self.foo - 44 - end - class MyInnerNamespace - def self.baz - 90 - end + def self.foo + 44 + end + + class MyInnerNamespace + def self.baz + 90 end + end end + class MyOtherNamespace - def self.foo - -2 - end + def self.foo + -2 + end end p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 @@ -42,12 +44,15 @@ class Example 5 end end + class MyNamespace + class Example def self.example 10 end end + def self.call_example p Example::example # => 10 p ::Example::example # => 5 diff --git a/concepts/namespaces/introduction.md b/concepts/namespaces/introduction.md index a5942b54d1..4fc10f8c8b 100755 --- a/concepts/namespaces/introduction.md +++ b/concepts/namespaces/introduction.md @@ -13,19 +13,21 @@ They are used together by prefixing their respective namespaces. ```ruby class MyNamespace - def self.foo - 44 - end - class MyInnerNamespace - def self.baz - 90 - end + def self.foo + 44 + end + + class MyInnerNamespace + def self.baz + 90 end + end end + class MyOtherNamespace - def self.foo - -2 - end + def self.foo + -2 + end end p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 @@ -42,12 +44,15 @@ class Example 5 end end + class MyNamespace + class Example def self.example 10 end end + def self.call_example p Example::example # => 10 p ::Example::example # => 5 diff --git a/exercises/concept/last-will/.docs/introduction.md b/exercises/concept/last-will/.docs/introduction.md index a5942b54d1..4fc10f8c8b 100755 --- a/exercises/concept/last-will/.docs/introduction.md +++ b/exercises/concept/last-will/.docs/introduction.md @@ -13,19 +13,21 @@ They are used together by prefixing their respective namespaces. ```ruby class MyNamespace - def self.foo - 44 - end - class MyInnerNamespace - def self.baz - 90 - end + def self.foo + 44 + end + + class MyInnerNamespace + def self.baz + 90 end + end end + class MyOtherNamespace - def self.foo - -2 - end + def self.foo + -2 + end end p MyNamespace::foo + MyOtherNamespace::foo * MyNamespace::MyInnerNamespace::baz # => -136 @@ -42,12 +44,15 @@ class Example 5 end end + class MyNamespace + class Example def self.example 10 end end + def self.call_example p Example::example # => 10 p ::Example::example # => 5 diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb index 5434b88b6b..4e505d3609 100644 --- a/exercises/concept/last-will/.meta/exemplar.rb +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -4,11 +4,13 @@ def self.bank_number_part(secret_modifier) zhang_part = 8541 (zhang_part * secret_modifier) % 10000 end + class Red def self.code_fragment 512 end end + class Blue def self.code_fragment 677 @@ -22,11 +24,13 @@ def self.bank_number_part(secret_modifier) khan_part = 4142 (khan_part * secret_modifier) % 10000 end + class Red def self.code_fragment 148 end end + class Blue def self.code_fragment 875 @@ -40,11 +44,13 @@ def self.bank_number_part(secret_modifier) garcia_part = 4023 (garcia_part * secret_modifier) % 10000 end + class Red def self.code_fragment 118 end end + class Blue def self.code_fragment 923 diff --git a/exercises/concept/last-will/last_will.rb b/exercises/concept/last-will/last_will.rb index d6fd817e54..2d45c5f12c 100755 --- a/exercises/concept/last-will/last_will.rb +++ b/exercises/concept/last-will/last_will.rb @@ -6,11 +6,13 @@ def self.bank_number_part(secret_modifier) zhang_part = 8541 (zhang_part * secret_modifier) % 10000 end + class Red def self.code_fragment 512 end end + class Blue def self.code_fragment 677 @@ -24,11 +26,13 @@ def self.bank_number_part(secret_modifier) khan_part = 4142 (khan_part * secret_modifier) % 10000 end + class Red def self.code_fragment 148 end end + class Blue def self.code_fragment 875 @@ -42,11 +46,13 @@ def self.bank_number_part(secret_modifier) garcia_part = 4023 (garcia_part * secret_modifier) % 10000 end + class Red def self.code_fragment 118 end end + class Blue def self.code_fragment 923 From 0d462443749aafd4f1b68d1dd3c0ac8f9a7271ca Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Thu, 14 May 2026 06:50:23 +0300 Subject: [PATCH 15/17] Corrections. --- exercises/concept/last-will/.meta/exemplar.rb | 12 ++--- exercises/concept/last-will/last_will.rb | 12 ++--- exercises/concept/last-will/last_will_test.rb | 44 +++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/exercises/concept/last-will/.meta/exemplar.rb b/exercises/concept/last-will/.meta/exemplar.rb index 4e505d3609..159d386ee1 100644 --- a/exercises/concept/last-will/.meta/exemplar.rb +++ b/exercises/concept/last-will/.meta/exemplar.rb @@ -1,8 +1,8 @@ # Secret knowledge of the Zhang family: class Zhang def self.bank_number_part(secret_modifier) - zhang_part = 8541 - (zhang_part * secret_modifier) % 10000 + zhang_part = 8_541 + (zhang_part * secret_modifier) % 10_000 end class Red @@ -21,8 +21,8 @@ def self.code_fragment # Secret knowledge of the Khan family: class Khan def self.bank_number_part(secret_modifier) - khan_part = 4142 - (khan_part * secret_modifier) % 10000 + khan_part = 4_142 + (khan_part * secret_modifier) % 10_000 end class Red @@ -41,8 +41,8 @@ def self.code_fragment # Secret knowledge of the Garcia family: class Garcia def self.bank_number_part(secret_modifier) - garcia_part = 4023 - (garcia_part * secret_modifier) % 10000 + garcia_part = 4_023 + (garcia_part * secret_modifier) % 10_000 end class Red diff --git a/exercises/concept/last-will/last_will.rb b/exercises/concept/last-will/last_will.rb index 2d45c5f12c..d8cf48028f 100755 --- a/exercises/concept/last-will/last_will.rb +++ b/exercises/concept/last-will/last_will.rb @@ -3,8 +3,8 @@ # Secret knowledge of the Zhang family: class Zhang def self.bank_number_part(secret_modifier) - zhang_part = 8541 - (zhang_part * secret_modifier) % 10000 + zhang_part = 8_541 + (zhang_part * secret_modifier) % 10_000 end class Red @@ -23,8 +23,8 @@ def self.code_fragment # Secret knowledge of the Khan family: class Khan def self.bank_number_part(secret_modifier) - khan_part = 4142 - (khan_part * secret_modifier) % 10000 + khan_part = 4_142 + (khan_part * secret_modifier) % 10_000 end class Red @@ -43,8 +43,8 @@ def self.code_fragment # Secret knowledge of the Garcia family: class Garcia def self.bank_number_part(secret_modifier) - garcia_part = 4023 - (garcia_part * secret_modifier) % 10000 + garcia_part = 4_023 + (garcia_part * secret_modifier) % 10_000 end class Red diff --git a/exercises/concept/last-will/last_will_test.rb b/exercises/concept/last-will/last_will_test.rb index 93ffa9b5b8..f1bd37e6d9 100755 --- a/exercises/concept/last-will/last_will_test.rb +++ b/exercises/concept/last-will/last_will_test.rb @@ -3,39 +3,39 @@ class LastWillTest < Minitest::Test def test_family_secrets_unaltered - #skip - assert_equal ::Zhang::bank_number_part(1), 8541 - assert_equal ::Zhang::bank_number_part(3), 8541 * 3 % 10000 - assert_equal ::Khan::bank_number_part(1), 4142 - assert_equal ::Khan::bank_number_part(3), 4142 * 3 % 10000 - assert_equal ::Garcia::bank_number_part(1), 4023 - assert_equal ::Garcia::bank_number_part(3), 4023 * 3 % 10000 - assert_equal ::Zhang::Red::code_fragment, 512 - assert_equal ::Khan::Red::code_fragment, 148 - assert_equal ::Garcia::Red::code_fragment, 118 - assert_equal ::Zhang::Blue::code_fragment, 677 - assert_equal ::Khan::Blue::code_fragment, 875 - assert_equal ::Garcia::Blue::code_fragment, 923 + # skip + assert_equal ::Zhang.bank_number_part(1), 8_541 + assert_equal ::Zhang.bank_number_part(3), 8_541 * 3 % 10_000 + assert_equal ::Khan.bank_number_part(1), 4_142 + assert_equal ::Khan.bank_number_part(3), 4_142 * 3 % 10_000 + assert_equal ::Garcia.bank_number_part(1), 4_023 + assert_equal ::Garcia.bank_number_part(3), 4_023 * 3 % 10_000 + assert_equal ::Zhang::Red.code_fragment, 512 + assert_equal ::Khan::Red.code_fragment, 148 + assert_equal ::Garcia::Red.code_fragment, 118 + assert_equal ::Zhang::Blue.code_fragment, 677 + assert_equal ::Khan::Blue.code_fragment, 875 + assert_equal ::Garcia::Blue.code_fragment, 923 end def test_account_number_assembly_method_in_correct_namespace - #skip - assert ::EstateExecutor.respond_to?(:assemble_account_number) + # skip + assert_respond_to(::EstateExecutor, :assemble_account_number) end def test_account_number_assembly_method_works - #skip - assert_equal ::EstateExecutor::assemble_account_number(1), 16706 - assert_equal ::EstateExecutor::assemble_account_number(23), 14238 + # skip + assert_equal ::EstateExecutor.assemble_account_number(1), 16_706 + assert_equal ::EstateExecutor.assemble_account_number(23), 14_238 end def test_code_fragment_number_assembly_method_in_correct_namespace - #skip - assert ::EstateExecutor.respond_to?(:assemble_code) + # skip + assert_respond_to(::EstateExecutor, :assemble_code) end def test_code_fragments_fit - #skip - assert_equal ::EstateExecutor::assemble_code, 1925550 + # skip + assert_equal ::EstateExecutor.assemble_code, 1_925_550 end end From 28e3a4d7c503446fcfacac07989fdf736302ad8f Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Thu, 14 May 2026 06:57:38 +0300 Subject: [PATCH 16/17] Corrections. --- config.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config.json b/config.json index 398f48312f..bc559fcbe4 100644 --- a/config.json +++ b/config.json @@ -188,6 +188,18 @@ "ostruct" ] }, + { + "slug": "last-will", + "name": "Last Will", + "uuid": "", + "concepts": [ + "namespaces" + ], + "prerequisites": [ + "basics", + "modules" + ] + }, { "slug": "moviegoer", "name": "Moviegoer", @@ -1624,6 +1636,11 @@ "slug": "multiple-assignment-and-decomposition", "name": "Multiple Assignment and Decomposition" }, + { + "uuid": "", + "slug": "namespaces", + "name": "Namespaces" + }, { "uuid": "fa482f4a-19d6-4d13-ad9e-5121c536dc76", "slug": "ostruct", From f546027a0a154aac4990592c2149af283bbd6dca Mon Sep 17 00:00:00 2001 From: Vaia Patta Date: Thu, 14 May 2026 15:26:39 +0300 Subject: [PATCH 17/17] UUIDs --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index bc559fcbe4..569dd04d8b 100644 --- a/config.json +++ b/config.json @@ -191,7 +191,7 @@ { "slug": "last-will", "name": "Last Will", - "uuid": "", + "uuid": "74b09c2d-916c-4c05-87b1-a348f8828733", "concepts": [ "namespaces" ], @@ -1637,7 +1637,7 @@ "name": "Multiple Assignment and Decomposition" }, { - "uuid": "", + "uuid": "80baa40d-ea8d-4958-940d-8c222be71a00", "slug": "namespaces", "name": "Namespaces" },