From 343abd405ca3ba245b506a2c7abc8a27d0788d72 Mon Sep 17 00:00:00 2001 From: Siolobe <86779354+peter-bachowski@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:40:02 -0700 Subject: [PATCH 1/7] Ruby Hash Map Data Structure: Improve link text descriptiveness (#28354) * change the position of several links and remove one * Fix all linter errors * Change link positions for hash maps using buckets and usages of prime numbers in hash functions --- ruby/computer_science/hash_map_data_structure.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ruby/computer_science/hash_map_data_structure.md b/ruby/computer_science/hash_map_data_structure.md index 280b5b4b689..d5b4a7f1eda 100644 --- a/ruby/computer_science/hash_map_data_structure.md +++ b/ruby/computer_science/hash_map_data_structure.md @@ -193,7 +193,7 @@ The growth of our hash map has the complexity of `O(n)` at all times.
- Read [What are Hash Functions and How to choose a good Hash Function](https://www.geeksforgeeks.org/what-are-hash-functions-and-how-to-choose-a-good-hash-function) for a more technical overview of a hash function. -- Watch this video from CS50 that [explains the concept of hash maps using buckets](https://www.youtube.com/watch?v=btT4bCOvqjs). +- Watch this video from CS50 that explains the concept of [hash maps using buckets](https://www.youtube.com/watch?v=btT4bCOvqjs).
@@ -210,5 +210,6 @@ The following questions are an opportunity to reflect on key topics in this less This section contains helpful links to related content. It isn't required, so consider it supplemental. -- This discussion goes through the [usage of prime numbers](https://stackoverflow.com/questions/299304/why-does-javas-hashcode-in-string-use-31-as-a-multiplier/299748) +- This discussion goes through the [usages of prime numbers in hash functions](https://stackoverflow.com/questions/299304/why-does-javas-hashcode-in-string-use-31-as-a-multiplier/299748). + - The [pigeonhole principle](https://en.wikipedia.org/wiki/Pigeonhole_principle) mathematically guarantees collisions when there are more nodes than boxes. From c118dc2b7be01efce4eb8dd0a3c3f5475fa0d1ec Mon Sep 17 00:00:00 2001 From: Midlife Mechanicus <42699076+MidlifeMechanicus@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:42:26 +0100 Subject: [PATCH 2/7] Remove unnecessary link (#28360) --- .../object_oriented_programming.md | 1 - 1 file changed, 1 deletion(-) diff --git a/ruby/object_oriented_programming_basics/object_oriented_programming.md b/ruby/object_oriented_programming_basics/object_oriented_programming.md index c8c66e3500b..6c3181fd3d3 100644 --- a/ruby/object_oriented_programming_basics/object_oriented_programming.md +++ b/ruby/object_oriented_programming_basics/object_oriented_programming.md @@ -47,7 +47,6 @@ The following questions are an opportunity to reflect on key topics in this less This section contains helpful links to related content. It isn't required, so consider it supplemental. - [Kevin Berridge's video presentation](http://vimeo.com/91672848) covers major themes of practical object-oriented design, with many references to Sandi Metz's book, in about 40 minutes. -- If you need a variable refresher, check out [Zetcode's Variables section](https://zetcode.com/lang/rubytutorial/variables/). - If you want more examples to code along with, check out [Zetcode's OOP section](http://zetcode.com/lang/rubytutorial/oop/) and [Zetcode's second OOP section](https://zetcode.com/lang/rubytutorial/oop2/) until they start talking about exceptions (~80% of the way down). - After you have completed several OOP projects, the following books by Sandi Metz are essential to build on the foundational concepts in this lesson. - [99 Bottles of OOP](https://sandimetz.com/99bottles) is a hands-on workbook that you should code along with to get the most out of it. This is a great resource if you feel uncertain about OOP concepts and would like to guided through refactoring examples and explanations. From 8ab619d47852f0b1a9be6bcbb059e09f9da61b2c Mon Sep 17 00:00:00 2001 From: Kimberley Le Bherz Date: Mon, 8 Jul 2024 21:44:12 +1000 Subject: [PATCH 3/7] Rails Pathway: Improve accessibility of link text (#28350) * Rails Pathway: Update links to be accessible & descriptive * Rails Pathway: Update links to be accessible & descriptive * Fix lint errors --- ruby/conclusion/conclusion.md | 3 +- .../introduction_to_rspec.md | 58 +++++++++---------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/ruby/conclusion/conclusion.md b/ruby/conclusion/conclusion.md index 838fcc34cfe..92e9308ab64 100644 --- a/ruby/conclusion/conclusion.md +++ b/ruby/conclusion/conclusion.md @@ -1,11 +1,12 @@ ### You did it! + Ruby is conquered. You're now a ninja.... okay, that's a bit hyperbolic but the fact is that you now know more than enough Ruby to take on Rails like a Boss. And, actually, the real secret is that the hard part is over. Getting to this point is the most difficult part of the learning curve. Sure, you've still got plenty to learn, but the real conceptual leaps have already been made. You can think like a programmer now and should be able to figure out how to appropriately Google for pretty much anything you don't already know. If you know Ruby, the world is sort of opened up for you. Want to learn Python? That would be a whole lot easier now. Nervous about Rails? Don't be. Rails is just Ruby that's been packaged up to do lots of stuff for you. With what you know, you'll have a much easier time "seeing the matrix" and understanding what Rails is up to. Even JavaScript should make a whole lot more sense to you once we get back to it. -Before you move on, we would like your feedback [here](https://docs.google.com/forms/d/e/1FAIpQLSdYksRBRg_0GzcYxzm5Csikfhj2Nceh2ifMYRmfMH6quwRRDw/viewform?usp=sf_link). Getting user (you) feedback is important so we can continue to improve the curriculum and get an idea of your experience. So that's it, you're more than ready to go ahead and take on Rails. **Congratulations!!!** +Before you move on, we would love it if you could [send us your feedback on the Ruby course](https://docs.google.com/forms/d/e/1FAIpQLSdYksRBRg_0GzcYxzm5Csikfhj2Nceh2ifMYRmfMH6quwRRDw/viewform?usp=sf_link). Getting user (you) feedback is important so we can continue to improve the curriculum and get an idea of your experience. So that's it, you're more than ready to go ahead and take on Rails. **Congratulations!!!** ### Additional resources diff --git a/ruby/testing_ruby_with_rspec/introduction_to_rspec.md b/ruby/testing_ruby_with_rspec/introduction_to_rspec.md index 05ae0fee58a..ae8aef4d9f5 100644 --- a/ruby/testing_ruby_with_rspec/introduction_to_rspec.md +++ b/ruby/testing_ruby_with_rspec/introduction_to_rspec.md @@ -1,6 +1,6 @@ ### Introduction -In the previous lesson, we established the utility of [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development) (TDD) in maintaining your code and sanity. In this lesson, we'll introduce you to your new best friend, the [RSpec](http://rspec.info/) testing framework. It's one of the most popular testing frameworks, having been downloaded more than [700 million times](https://rubygems.org/gems/rspec), at the time of this writing, and having been ported for use in [Rails testing](https://rubygems.org/gems/rspec-rails). +In the previous lesson, we established the utility of [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development) (TDD) in maintaining your code and sanity. In this lesson, we'll introduce you to your new best friend, the [RSpec](http://rspec.info/) testing framework. It's one of the most popular testing frameworks, having been downloaded more than 700 million times, at the time of this writing, and having been ported for use in [Rails testing](https://rubygems.org/gems/rspec-rails). ### Lesson overview @@ -8,9 +8,7 @@ This section contains a general overview of topics that you will learn in this l - Know what RSpec is. - Know how to install RSpec. -- Understand the basic RSpec syntax: - - `describe`. - - `it`. +- Understand the basic RSpec syntax: `describe` and `it`. ### Introduction to RSpec @@ -18,7 +16,7 @@ This section contains a general overview of topics that you will learn in this l At the most basic level, RSpec is a Domain Specific Language written in Ruby, or, for the rest of us, a language specialized for a particular task. In this case, the task is testing Ruby code. The `rspec` gem comes packaged with all you need to get started, including five gems: `rspec`, `rspec-core`, `rspec-expectations`, `rspec-mocks`, and `rspec-support`. -At this point, you may be wondering, _Why RSpec? Surely, there are other frameworks out there_, and you'd be right. There are. In fact, at one point, Ruby came bundled with [Test::Unit](https://github.com/test-unit/test-unit) and later [Minitest](https://github.com/seattlerb/minitest) as part of its standard library, the latter of which lives on in Rails. If you tend to be pessimistic (Sorry, we meant _realistic_), then the [Wrong](https://github.com/sconover/wrong) testing framework might be your cup of tea. Or perhaps you're hungry and in the mood for something more substantial, in which case a side of [Bacon](https://github.com/chneukirchen/bacon) might be what you need. At the end of the day, it doesn't matter which framework you choose as long as you cultivate your testing skills. RSpec's wider adoption, especially in the Rails community, is certainly reason enough to warrant familiarity with it, but implementing tests should be the end-all and be-all, rather than choosing a particular framework. +At this point, you may be wondering, *Why RSpec? Surely, there are other frameworks out there*, and you'd be right. There are. In fact, at one point, Ruby came bundled with [Test::Unit](https://github.com/test-unit/test-unit) and later [Minitest](https://github.com/seattlerb/minitest) as part of its standard library, the latter of which lives on in Rails. If you tend to be pessimistic (Sorry, we meant *realistic*), then the [Wrong](https://github.com/sconover/wrong) testing framework might be your cup of tea. Or perhaps you're hungry and in the mood for something more substantial, in which case a side of [Bacon](https://github.com/chneukirchen/bacon) might be what you need. At the end of the day, it doesn't matter which framework you choose as long as you cultivate your testing skills. RSpec's wider adoption, especially in the Rails community, is certainly reason enough to warrant familiarity with it, but implementing tests should be the end-all and be-all, rather than choosing a particular framework. But enough [proselytizing](https://www.dictionary.com/browse/proselytizing). Strap your helmet and buckle up; we're going to jump right in. @@ -45,9 +43,9 @@ That's it. Within two steps, you're up and running with RSpec. That wasn't so ha How 'bout a test to see the syntax? Let's create a brand new "project" to get going. Create a new directory called "ruby_testing", change into it, and initiate RSpec. -``` -$ mkdir ruby_testing && cd ruby_testing -$ rspec --init +```bash +mkdir ruby_testing && cd ruby_testing +rspec --init ``` As expected, the output will read: @@ -57,7 +55,7 @@ As expected, the output will read: create spec/spec_helper.rb ``` -Run the tests from your terminal by using the `rspec` command, which will return "No examples found." That really shouldn't surprise you, because we haven't written any tests yet. If you're still shocked... maybe take a short break, or come say hello to us in our [Discord](https://discord.gg/fbFCkYabZB) back-end channel. +Run the tests from your terminal by using the `rspec` command, which will return "No examples found." That really shouldn't surprise you, because we haven't written any tests yet. If you're still shocked... maybe take a short break, or come say hello to us in [our Discord server](https://discord.gg/fbFCkYabZB)! ```bash No examples found. @@ -103,9 +101,9 @@ end That's basically it. One more time, from the top: 1. `describe` the class -2. `describe` the method example group. Conventionally, the string argument for instance methods are written as "#method", while string arguments for class methods are written as ".method". -3. Write your test case/example with `it`. -4. Write your expectation using `expect`. The `expect` method is also chained with `.to` for positive expectations, or `.to_not`/`.not_to` for negative expectations. We prefer `.not_to`. Also, limit one expect clause per test case. +1. `describe` the method example group. Conventionally, the string argument for instance methods are written as "#method", while string arguments for class methods are written as ".method". +1. Write your test case/example with `it`. +1. Write your expectation using `expect`. The `expect` method is also chained with `.to` for positive expectations, or `.to_not`/`.not_to` for negative expectations. We prefer `.not_to`. Also, limit one expect clause per test case. #### Passing code @@ -181,7 +179,7 @@ rspec ./spec/calculator_spec.rb:5 # Calculator#add returns the sum of two number Our first failure is denoted by the `F` at the top of the output. Congratulations! You've made it to the "red" portion of the "red-green-refactor" cycle of TDD. RSpec provides a list of all the failures, with the expected vs. actual output of the method being tested. At the bottom of your output, RSpec also points to the line of the failing test, which in this case is where our `it` block started. -Getting this method to "green" shouldn't be too difficult. RSpec clearly provides a reason for the failure: it expected the output to be `7` when we provided the method with `(5, 2)` as the parameters. Instead, it returned `nil`. Why might that be? Well, our `#add` _does_ take two parameters...but it does nothing with them! Add the minimum amount of code necessary to get your test to pass: +Getting this method to "green" shouldn't be too difficult. RSpec clearly provides a reason for the failure: it expected the output to be `7` when we provided the method with `(5, 2)` as the parameters. Instead, it returned `nil`. Why might that be? Well, our `#add` *does* take two parameters...but it does nothing with them! Add the minimum amount of code necessary to get your test to pass: ```ruby #lib/calculator.rb @@ -202,7 +200,7 @@ Finished in 0.0032 seconds (files took 0.14864 seconds to load) 1 example, 0 failures ``` -At this point, refactoring isn't necessary. The `#add` method is essentially a one line method. As you progress in your Ruby learning, however, you might find your methods getting more complex, and you might find that you have to make extra efforts to abide by [SOLID]() principles. When that time comes, using RSpec and the "red-green-refactor" cycle will allow you to code with confidence, knowing that your classes and their behaviors continue to meet your specified expectations. +At this point, refactoring isn't necessary. The `#add` method is essentially a one line method. As you progress in your Ruby learning, however, you might find your methods getting more complex, and you might find that you have to make extra efforts to abide by [SOLID principles](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)). When that time comes, using RSpec and the "red-green-refactor" cycle will allow you to code with confidence, knowing that your classes and their behaviors continue to meet your specified expectations. ### Assignment @@ -230,28 +228,30 @@ It's time to put your newfound knowledge to good use. Let's break our `Calculato end ``` -2. Write a test for a new `Calculator` method (`#multiply`, `#subtract`, or `#divide`) using a new `describe` block. Include at least one `it` block with an appropriate expectation clause. Get it to pass, and refactor if necessary. -3. In the terminal, try running your failing or passing tests with `rspec --format documentation`. What's different? -4. RSpec reads command line configurations from `.rspec`, one of the two files generated when RSpec is initialized in a project. If you liked the output you got with `--format documentation`, you can use the `.rspec` file to hold that flag. In doing so, you won't have to type it in every time you run your test suite. Open the file in your text editor and, on a new line, add `--format documentation`. For more information on configuring RSpec, [see the docs here](http://rspec.info/features/3-12/rspec-core/configuration/). +1. Write a test for a new `Calculator` method (`#multiply`, `#subtract`, or `#divide`) using a new `describe` block. Include at least one `it` block with an appropriate expectation clause. Get it to pass, and refactor if necessary. +1. In the terminal, try running your failing or passing tests with `rspec --format documentation`. What's different? +1. RSpec reads command line configurations from `.rspec`, one of the two files generated when RSpec is initialized in a project. If you liked the output you got with `--format documentation`, you can use the `.rspec` file to hold that flag. In doing so, you won't have to type it in every time you run your test suite. Open the file in your text editor and, on a new line, add `--format documentation`. For more information, you can read more about [configuring RSpec](http://rspec.info/features/3-12/rspec-core/configuration/). + ### Knowledge check -This section contains questions for you to check your understanding of this lesson. If you’re having trouble answering the questions below on your own, review the material above to find the answer. -- What do you name the folder that contains your test files? -- What does the keyword `describe` define? -- What does the keyword `it` define? -- How many expect clauses can you write for one test case? -- What are some of RSpec's equality matchers? -- How do we tell RSpec where to find the code to be tested? +The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. + +- [What do you name the folder that contains your test files?](#tests-folder) +- [What does the keyword `describe` define?](#keyword-describe) +- [What does the keyword `it` define?](#keyword-it) +- [How many expect clauses can you write for one test case?](#expect-clauses) +- [What are some of RSpec's equality matchers?](http://rspec.info/features/3-12/rspec-expectations/built-in-matchers/equality/) +- [How do we tell RSpec where to find the code to be tested?](#require) ### Additional resources This section contains helpful links to related content. It isn't required, so consider it supplemental. -- [This Youtube video](https://www.youtube.com/watch?v=K6RPMhcRICE) gives an excellent overview of the fundamentals of Rspec, and gives a brief overview of some concepts that will be mentioned in the next lesson. -- For a more thorough overview of RSpec, read through the [RSpec section](http://testing-for-beginners.rubymonstas.org/rspec.html) of Ruby Monsta's [Testing for Beginners book](http://testing-for-beginners.rubymonstas.org/index.html). +- This Youtube video gives an excellent [overview of the fundamentals of Rspec](https://www.youtube.com/watch?v=K6RPMhcRICE), and gives a brief overview of some concepts that will be mentioned in the next lesson. +- For a more thorough overview of RSpec, read through the [RSpec section of Ruby Monsta’s "Testing for Beginners" book](http://testing-for-beginners.rubymonstas.org/rspec.html). - Briefly look over [RSpec's other matchers](http://rspec.info/features/3-12/rspec-expectations/built-in-matchers/) if you haven't done so already. -- Briefly look over the RSpec styling and syntax recommended by [BetterSpecs](http://www.betterspecs.org/) and read through the first six guidelines. -- [This RSpec Cheat Sheet](https://devhints.io/rspec) should help you avoid Googling every new bit of syntax. -- Solidify these concepts with a [shameless plug](https://medium.com/@mindovermiles262/getting-started-with-rspec-part-1-9418909f5e53) from another Odin Project contributor. +- Briefly look over [BetterSpecs' recommended RSpec styling and syntax](http://www.betterspecs.org/) and read through the first six guidelines. +- This [RSpec Cheat Sheet](https://devhints.io/rspec) should help you avoid Googling every new bit of syntax. +- [Getting Started with RSpec Part 1](https://mindovermiles262.medium.com/getting-started-with-rspec-part-1-9418909f5e53): Solidify these concepts with a shameless plug from another Odin Project contributor. From 8cc11c30d97148c352382b99e5d4effedccde757 Mon Sep 17 00:00:00 2001 From: Ace Da Costa Date: Mon, 8 Jul 2024 11:45:47 +0000 Subject: [PATCH 4/7] Correct grammar and Improve clarity (#28144) --- .../introduction/motivation_and_mindset.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/foundations/introduction/motivation_and_mindset.md b/foundations/introduction/motivation_and_mindset.md index 9e1e2269550..47dc691bf84 100644 --- a/foundations/introduction/motivation_and_mindset.md +++ b/foundations/introduction/motivation_and_mindset.md @@ -2,7 +2,7 @@ Learning to code is incredibly rewarding but can also be difficult and frustrating. Like any skill worth knowing, it takes time to acquire, and it can't be learned in a weekend or even a month. With that said, we believe anyone can learn how to program as long as they are willing to put in the time and effort. -So before we get into the meat of the curriculum, we're going to go over the following to help you get the most out of The Odin Project: the things that will help you succeed in your goal of learning to code and the pitfalls that you should try to avoid. +So before we get into the meat of the curriculum, we'll cover the following aspects to help you get the most out of The Odin Project: factors that will help you succeed in learning to code and the pitfalls that you should try to avoid. ### Motivation @@ -54,7 +54,7 @@ You will inevitably get stuck at some point in the curriculum, perhaps due to a - Take a break: Allow your diffuse learning state to work on the problem. - Ask for help in the [TOP Discord server](https://discord.gg/theodinproject); come prepared with your research. People will be more willing to help you when they can see you have already put effort into trying to figure out the solution on your own. -Additionally, feel free to follow the diagram below that should help you going through problems that you may come across: +Additionally, feel free to follow the diagram below to help you navigate problems that you may come across: ![diagram to help learners go through problems when they are stuck](https://cdn.statically.io/gh/TheOdinProject/curriculum/978ba0e91a6a47452de819246f4c495e6b092f54/foundations/introduction/motivation_and_mindset/imgs/00.png) @@ -64,13 +64,13 @@ As technology advances, we have seen some incredible tools emerge that can help While these tools are amazing, learners should be aware of the impacts that using such tools can have on core competency. David Humphrey, a computer science professor, [wrote about ChatGPT and its potentially negative impacts on core learning.](https://blog.humphd.org/cheatgpt/) It is a good read about the pitfalls of using generative AI in an educational context. -For learners that are new to programming, tools like ChatGPT or Github Copilot can result in some blindspots and gaps in your knowledge. +For learners who are new to programming, tools like ChatGPT or GitHub Copilot can result in blindspots and gaps in your knowledge. 1. By using a generative AI, learners may miss the opportunity to discover how something works and why things are done that way. -1. Asking good questions is an important skill to have, and using generative AI to skip asking people (like our helpful Discord community) means that your development of this skill is delayed. +1. Asking good questions is an important skill, and relying on generative AI instead of asking people (like our helpful Discord community) can delay the development of this skill. 1. Learning to talk about the code that one writes is another important skill. In a professional environment, it is highly likely that you will be doing code reviews where you have to explain the how and why behind what you are presenting. Using the Odin community to ask good questions about your code when you require help can help develop this skill as well. 1. As David Humphrey mentions, the output of generative AI must be closely scrutinized, and learners who are new to programming generally don't have a good overall understanding to be able to determine if the output is good or bad. -1. While learning how to provide good prompts to an AI tool is a skill, it is one that is supplementary to developing foundational programming skills. The Odin curriculum strives to teach that foundational skill. +1. While learning how to provide good prompts to an AI tool is a skill, it is supplementary to developing foundational programming skills. The Odin curriculum strives to teach that foundational skill. 1. AI tools are designed to answer questions and are not designed to help learners develop research and problem solving skills. If you ask an AI for information, it will provide information to you. If you ask a human, they may invite you to share your understanding of the problem and offer some guidance on how to discover a solution. 1. Without practice in research, problem solving and critical thinking, interviews could be a struggle since it is very likely that applicants would not be allowed to use AI tools. @@ -80,11 +80,11 @@ We do not recommend using AI tools for your learning. You will have more success with Odin by putting **consistent** time into it rather than working on it once a week. Building a habit of studying every day at a specific time and with a specific goal will ensure that you make consistent progress. -It may take you longer than others to grasp concepts, or it may take you less time. This doesn't mean you're smarter or dumber than others, it means you've had differing life experiences that may or may not have prepared you for learning this stuff. Someone who grew up around an engineer may have some advantages over someone who didn't, but it doesn't mean you can't learn those skills. +It may take you longer than others to grasp concepts, or it may take you less time. This doesn't mean you're smarter or dumber than others, it means you've had differing life experiences that may or may not have prepared you for learning those concepts. Someone who grew up around an engineer may have some advantages over someone who didn't, but it doesn't mean you can't learn those skills. -The Odin Project isn't like college or university, it is self paced and allows you to get a really solid grasp of concepts before moving on. In school, you're forced to keep up or you will fail. The difference here is that coming into The Odin Project, you're not expected to have much knowledge; there are no prerequisites. We've had people be successful coming through here who only knew how to check their email with a computer. We've also seen success from computer science degree holders. Treating The Odin Project like a static timeline is understandable, but is a sign of misplaced expectations. You don't know what you don't know yet, and that's OK! There are no due-dates on things in The Odin Project so you can spend the time to do it right and discuss the topics. +The Odin Project isn't like college or university, it is self-paced and allows you to get a solid grasp of concepts before moving on. In school, you're forced to keep up, or you will fail. The difference with The Odin Project is that you’re not expected to have much prior knowledge; there are no prerequisites. We've had people be successful coming through here who only knew how to check their email with a computer. We've also seen success from computer science degree holders. Treating The Odin Project like a static timeline is understandable, but is a sign of misplaced expectations. You don't know what you don't know yet, and that's OK! There are no due-dates on lessons in The Odin Project, so you can spend enough time to do it right and discuss the topics. -Deadlines cause un-needed stress. Since The Odin Project is a free and open platform, you are not beholden to a deadline. Creating your own deadlines is a good way to rush concepts that should not be rushed. This course is very research based, meaning you will have to do research to complete tasks and projects. There's no telling if you can find the article or post that helps you in the right way, quickly to meet your deadlines, but we bet you learned a TON along the way that you can use in the future. People that do this kind of research and strive to write better solutions tend to become better developers in the future. There's no knowing how long it could take you to learn how to query stuff to find your answers. There are no solid guidelines on that. If you're doing The Odin Project because you need a high paying job *right-now*, you're not going to become a solid developer within the timeframe you have set. Stress and anxiety absolutely do not help you learn either. Relax and just enjoy the ride. +Deadlines cause unneeded stress. Since The Odin Project is a free and open platform, you are not beholden to a deadline. Creating your own deadlines can lead to rushing through concepts that should not be rushed. This course is very research based, meaning you will have to do research to complete tasks and projects. There’s no guarantee you will find the right article or post quickly enough to meet your deadlines, but you will likely learn a TON along the way that you can use in the future. People that do this kind of research and strive to write better solutions tend to become better developers in the future. There’s no way to know how long it will take you to learn how to query concepts to find your answers. There are no solid guidelines on that. If you're doing The Odin Project because you need a high-paying job *right now*, you’re unlikely to become a solid developer within the timeframe you have set. Stress and anxiety absolutely do not help you learn either. Relax and just enjoy the ride. Long story short: Don't worry, just go learn! @@ -131,13 +131,13 @@ Digital distractions are email and Facebook notifications and time-wasting websi Physical distractions are distractions from your environment, like a TV in the background or other people talking. These distractions can be just as damaging to your focus as digital distractions. -**Solution:** Find a quiet place to study where you can go to focus in your home. If that's not an option, you can use noise cancelling headphones to block out noisy distractions in your environment. There are also complimentary public and university libraries that are serene and comfortable. Some libraries even operate 24/7, uninterrupted. Beyond just providing a pleasant study space, the presence of others studying around you instills a sense of productivity. +**Solution:** Find a quiet place in your home where you can focus on your studies. If that's not an option, you can use noise cancelling headphones to block out noisy distractions in your environment. There are also complimentary public and university libraries that are serene and comfortable. Some libraries even operate 24/7, uninterrupted. Beyond just providing a pleasant study space, the presence of others studying around you instills a sense of productivity. #### Rabbit holes Because we cover so much material on The Odin Project and link to so many high quality courses and tools, it is easy for students to get pulled into rabbit holes by spending time trying to learn all there is to know about a subject that they aren't ready for or won't benefit them much. **We have put a lot of effort into structuring the curriculum** so that all of the important things that you need to know about web development are covered exactly when you need to know them. -**Solution:** Stick to the path laid out as much as possible. Try to limit time spent going down rabbit holes as these sidetracks can really ruin your momentum. +**Solution:** Stick to the path laid out as much as possible. Try to limit time spent going down rabbit holes, as these sidetracks can really ruin your momentum. #### Comparing yourself to others @@ -145,7 +145,7 @@ Students often compare themselves to others who are farther along in their codin **Solution:** Only compare yourself to your past self. Have your abilities and knowledge improved from where you were last week, last month, or last year? Be proud of the progress that you've made! -#### Counter productive note-taking +#### Counterproductive note-taking The Odin Project does not recommend taking a lot of notes throughout your web development educational journey because it can be time-consuming and often leads to wasted effort. @@ -153,7 +153,7 @@ The Odin Project does not recommend taking a lot of notes throughout your web de ### Conclusion -Learning any new skill is a journey full of speed bumps and obstacles to be overcome. We hope that the principles laid out here will put you in a much better position to succeed and get the most out of The Odin Project. +Learning any new skill is a journey full of speed bumps and obstacles to overcome. We hope that the principles laid out here will put you in a much better position to succeed and get the most out of The Odin Project. ### Assignment From c3423cb3d32f14f3c8b4f28a63623c2b986f0f06 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:51:13 +0100 Subject: [PATCH 5/7] Component Lifecycle Methods: Add link to canvas element (#27554) * Update component_lifecycle_methods.md * Update component_lifecycle_methods.md --- react/class_components/component_lifecycle_methods.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/class_components/component_lifecycle_methods.md b/react/class_components/component_lifecycle_methods.md index f97497591cc..e9976e45e51 100644 --- a/react/class_components/component_lifecycle_methods.md +++ b/react/class_components/component_lifecycle_methods.md @@ -16,7 +16,7 @@ The render function is the most used lifecycle method, and one that you've come ### componentDidMount() -This method is run after the component is mounted (inserted in the DOM tree). You should make any calls to fetch data that is needed for the component here. It is also a good place to do anything that is reliant on the component, such as drawing on a canvas element that you just rendered. +This method is run after the component is mounted (inserted in the DOM tree). You should make any calls to fetch data that is needed for the component here. It is also a good place to do anything that is reliant on the component, such as fetching from an API. ### componentDidUpdate() From 0199be6a9923e387d64ae8b185b1416917e76cfc Mon Sep 17 00:00:00 2001 From: Preslav Tsvetanov <119291608+Preslav977@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:40:01 +0300 Subject: [PATCH 6/7] Ruby: Improve accessibility of link text and fix markdown linting errors (#28362) * Added descriptive text to the links of the lessons and projects Bubble Sort, TicTacToe, OOP, and Files and Serialization. * Added the required text between the knowledge check and list in the Files and Serialization and ran the following scripts to fix the lint errors. * Fixed the linting errors, changed the lists to not be nested and amended the last sentence in additional resource in OOP Ruby path. * Improved the grammar in OOP lesson Ruby. --- .../project_bubble_sort.md | 2 +- .../files_and_serialization.md | 26 +++++++++++-------- .../object_oriented_programming.md | 9 +++---- .../project_tic_tac_toe.md | 8 +++--- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ruby/basic_ruby_projects/project_bubble_sort.md b/ruby/basic_ruby_projects/project_bubble_sort.md index 9d1759eb067..1c1989f6d03 100644 --- a/ruby/basic_ruby_projects/project_bubble_sort.md +++ b/ruby/basic_ruby_projects/project_bubble_sort.md @@ -4,7 +4,7 @@ Sorting algorithms are some of the earliest that you typically get exposed to in One of the simpler (but more processor-intensive) ways of sorting a group of items in an array is **bubble sort**, where each element is compared to the one next to it and they are swapped if the one on the left is larger than the one on the right. This continues until the array is eventually sorted. -Check out [this video from Harvard's CS50x on Bubble Sort](https://www.youtube.com/watch?v=8Kp-8OGwphY). +Check out this [video from Harvard’s CS50 on Bubble Sort](https://www.youtube.com/watch?v=8Kp-8OGwphY). There's also [an entry on Bubble Sort on Wikipedia](http://en.wikipedia.org/wiki/Bubble_sort) that's worth taking a look at. diff --git a/ruby/files_and_serialization/files_and_serialization.md b/ruby/files_and_serialization/files_and_serialization.md index c6ee0193058..2d3bb270ca4 100644 --- a/ruby/files_and_serialization/files_and_serialization.md +++ b/ruby/files_and_serialization/files_and_serialization.md @@ -25,26 +25,30 @@ This section contains a general overview of topics that you will learn in this l ### Assignment
+ 1. Read [Thoughtbot's I/O in Ruby](https://thoughtbot.com/blog/io-in-ruby). You can ignore both the 'Putting it all together' and the 'Working with disparate APIs' sections. - 2. Watch [icc0612's introduction to serialization](https://www.youtube.com/watch?v=uS37TujnLRw). It will explain the concept of serialization before you implement it in Ruby. - 3. Read [Choosing the Right Serialization Format](https://www.sitepoint.com/choosing-right-serialization-format/) for more information about the various serialization options you can choose from. - 4. Skim [Alan Skorkin's](http://www.skorks.com/2010/04/serializing-and-deserializing-objects-with-ruby/) post about serialization. Some of the code examples are outdated, but this post still contains relevant information. If you want to follow along with the code examples, copy and paste them into your code editor and use word wrap. - 5. Read the sections 'Ruby files' and 'Ruby directories' from the [Input/Output chapter of Zetcode's Ruby Tutorial](http://zetcode.com/lang/rubytutorial/io/) for examples of how to manipulate files and directories using the `File` and `Dir` classes. + 1. Watch [icc0612's introduction to serialization](https://www.youtube.com/watch?v=uS37TujnLRw). It will explain the concept of serialization before you implement it in Ruby. + 1. Read [Choosing the Right Serialization Format](https://www.sitepoint.com/choosing-right-serialization-format/) for more information about the various serialization options you can choose from. + 1. Skim [Alan Skorkin’s article about object serialization in Ruby](http://www.skorks.com/2010/04/serializing-and-deserializing-objects-with-ruby/). Some of the code examples are outdated, but this post still contains relevant information. If you want to follow along with the code examples, copy and paste them into your code editor and use word wrap. + 1. Read the sections 'Ruby files' and 'Ruby directories' from the [Input/Output chapter of Zetcode's Ruby Tutorial](http://zetcode.com/lang/rubytutorial/io/) for examples of how to manipulate files and directories using the `File` and `Dir` classes. +
### Knowledge check - * [How would you go through the lines of a file using an `IO` object?](https://thoughtbot.com/blog/io-in-ruby) - * [How would you take the Array `[1,2,3]` and serialize it into a JSON string format?](https://www.sitepoint.com/choosing-right-serialization-format/) - * [What are the benefits of YAML vs JSON vs MessagePack serialization formats?](https://www.sitepoint.com/choosing-right-serialization-format/) - * [How can you check if a file or directory exists?](http://zetcode.com/lang/rubytutorial/io/) - * [How can you list a directory's contents in the form of an array?](http://zetcode.com/lang/rubytutorial/io/) +The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. + +- [How would you go through the lines of a file using an `IO` object?](https://thoughtbot.com/blog/io-in-ruby) +- [How would you take the Array `[1,2,3]` and serialize it into a JSON string format?](https://www.sitepoint.com/choosing-right-serialization-format/) +- [What are the benefits of YAML vs JSON vs MessagePack serialization formats?](https://www.sitepoint.com/choosing-right-serialization-format/) +- [How can you check if a file or directory exists?](http://zetcode.com/lang/rubytutorial/io/) +- [How can you list a directory's contents in the form of an array?](http://zetcode.com/lang/rubytutorial/io/) ### Additional resources This section contains helpful links to related content. It isn't required, so consider it supplemental. -- [Everything You Need to know about Serialization in Ruby on Rails](https://blog.kiprosh.com/serialization_in_ruby_on_rails_part_one/) +- [Everything You Need to know about Serialization in Ruby on Rails](https://blog.kiprosh.com/serialization_in_ruby_on_rails_part_one/) - [Ruby Monk's section on Serializing](https://web.archive.org/web/20160505174806/http://rubymonk.com/learning/books/4-ruby-primer-ascent/chapters/45-more-classes/lessons/104-serializing) - [Short Example of Serialization](https://web.archive.org/web/20200627063721/http://rubylearning.com/satishtalim/object_serialization.html) from Ruby Learning -- How to [Read](https://www.youtube.com/watch?v=92li0A8d4io) and [Write](https://www.youtube.com/watch?v=FW9hDsMY1is) Files by Giraffe Academy \ No newline at end of file +- How to [Read](https://www.youtube.com/watch?v=92li0A8d4io) and [Write](https://www.youtube.com/watch?v=FW9hDsMY1is) Files by Giraffe Academy diff --git a/ruby/object_oriented_programming_basics/object_oriented_programming.md b/ruby/object_oriented_programming_basics/object_oriented_programming.md index 6c3181fd3d3..bcb4036512d 100644 --- a/ruby/object_oriented_programming_basics/object_oriented_programming.md +++ b/ruby/object_oriented_programming_basics/object_oriented_programming.md @@ -6,7 +6,7 @@ The concepts you'll learn here are often less specific to Ruby itself and more w There are two projects in this Object Oriented Programming Basics section, but this does not mean that you will only use OOP for these two projects. Ruby is a object-oriented language, so it is important to use OOP for all of the remaining projects. -There is a lot of reading in this lesson, so you are encouraged to code along with each example. If you find an example that does not make sense, ask for help in the `#ruby-help` channel in our [Discord](https://discord.gg/fbFCkYabZB) server. To get the most out of each example, try to apply what you learned by adding similar functionality on your own. +There is a lot of reading in this lesson, so you are encouraged to code along with each example. If you find an example that does not make sense, ask for help in the `#ruby-help` channel in [our Discord server](https://discord.gg/fbFCkYabZB). To get the most out of each example, try to apply what you learned by adding similar functionality on your own. ### Lesson overview @@ -26,7 +26,7 @@ This section contains a general overview of topics that you will learn in this l - [Ruby Explained: Inheritance and Scope](http://www.eriktrautman.com/posts/ruby-explained-inheritance-and-scope) 1. Read the article [Object Relationships in Basic Ruby](https://medium.com/@marcellamaki/object-relationships-in-basic-ruby-1af5773fff48) to see an example of how two classes can interact. 1. Read the [Bastard's Chapter on Error Handling](http://ruby.bastardsbook.com/chapters/exception-handling/) to reinforce your understanding of dealing with errors. -1. Do [Quiz #5](http://www.codequizzes.com/ruby/beginner/intro-object-oriented-programming) and [Quiz #7](http://www.codequizzes.com/ruby/beginner/modules-classes-inheritance) from Code Quizzes +1. Do this [quiz on introductory object-oriented programming](http://www.codequizzes.com/ruby/beginner/intro-object-oriented-programming) and this [quiz on modules, classes, and inheritance](http://www.codequizzes.com/ruby/beginner/modules-classes-inheritance) from Code Quizzes. @@ -48,6 +48,5 @@ This section contains helpful links to related content. It isn't required, so co - [Kevin Berridge's video presentation](http://vimeo.com/91672848) covers major themes of practical object-oriented design, with many references to Sandi Metz's book, in about 40 minutes. - If you want more examples to code along with, check out [Zetcode's OOP section](http://zetcode.com/lang/rubytutorial/oop/) and [Zetcode's second OOP section](https://zetcode.com/lang/rubytutorial/oop2/) until they start talking about exceptions (~80% of the way down). -- After you have completed several OOP projects, the following books by Sandi Metz are essential to build on the foundational concepts in this lesson. - - [99 Bottles of OOP](https://sandimetz.com/99bottles) is a hands-on workbook that you should code along with to get the most out of it. This is a great resource if you feel uncertain about OOP concepts and would like to guided through refactoring examples and explanations. - - [Practical Object-Oriented Design in Ruby](https://www.poodr.com/) is a traditional technical book with practical examples. This is a great resource after 99 Bottles or if you already feel like you fully understand OOP concepts. +- [99 Bottles of OOP](https://sandimetz.com/99bottles) is a hands-on workbook that you should code along with to get the most out of it. This is a great resource if, after completing several OOP projects, you still feel uncertain about OOP concepts and would like to be guided through some refactoring examples and explanations. +- [Practical Object-Oriented Design in Ruby](https://www.poodr.com/) is a traditional technical book with practical examples. This is a great resource if, after completing several OOP projects, you still feel uncertain about OOP concepts and would like to be guided through some refactoring examples and explanations. diff --git a/ruby/object_oriented_programming_basics/project_tic_tac_toe.md b/ruby/object_oriented_programming_basics/project_tic_tac_toe.md index 6d6f2b7066e..24aa1f16bd6 100644 --- a/ruby/object_oriented_programming_basics/project_tic_tac_toe.md +++ b/ruby/object_oriented_programming_basics/project_tic_tac_toe.md @@ -1,15 +1,17 @@ ### Introduction -Remember Tic Tac Toe? See [Wikipedia](http://en.wikipedia.org/wiki/Tic-tac-toe) if you can't remember the rules, or if you haven't ever played. It involves a couple of players, a board, checking for victory in a game loop... all the conditions that make it a fun little problem to solve using our newfound OOP sea legs. Let's build it! +Remember [Tic Tac Toe](https://en.wikipedia.org/wiki/Tic-tac-toe) (also known as "Noughts and Crosses")? It involves a couple of players, a board, checking for victory in a game loop... all the conditions that make it a fun little problem to solve using our newfound OOP sea legs. Let's build it! ### Assignment Build a tic-tac-toe game on the command line where two human players can play against each other and the board is displayed in between turns.
+ 1. Think about how you would set up the different elements within the game... What should be a class? Instance variable? Method? A few minutes of thought can save you from wasting an hour of coding. - 2. Build your game, taking care to not share information between classes any more than you have to. - 3. Post your solution below, then check out [this example solution from RosettaCode.org](http://rosettacode.org/wiki/Tic-tac-toe#Ruby). + 1. Build your game, taking care to not share information between classes any more than you have to. + 1. Post your solution below, then check out this [example Tic Tac Toe solution from RosettaCode.org](http://rosettacode.org/wiki/Tic-tac-toe#Ruby). +
### Additional resources From fa1cf4d262b937959f91f178f07ceb1daae32b02 Mon Sep 17 00:00:00 2001 From: Lakshya Tyagi <138753214+LAKSHYA201@users.noreply.github.com> Date: Tue, 9 Jul 2024 00:33:23 +0530 Subject: [PATCH 7/7] Advanced Ruby: Improve link text accessibility and fix lint errors (#28363) * docs:change assignment link text in pattern_matching.md * docs: made changes to blocks.md in advanced ruby * docs: made changes in link text in project_custom_enumerables.md * fix: fixed some linting errors in blocks.md and pattern_matching.md --- ruby/advanced_ruby/blocks.md | 14 ++-- ruby/advanced_ruby/pattern_matching.md | 65 ++++++++++--------- .../project_custom_enumerables.md | 2 +- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/ruby/advanced_ruby/blocks.md b/ruby/advanced_ruby/blocks.md index 499da59ccad..9487f0eade1 100644 --- a/ruby/advanced_ruby/blocks.md +++ b/ruby/advanced_ruby/blocks.md @@ -332,7 +332,7 @@ nested_array.select {|a, b| a + b > 10 } As you can see, `#select` has two arguments specified `|a, b|`, on each iteration we pass a single element of nested_array into the block. On the first iteration this is: `[1, 2]`, this array now, is deconstructed automatically (into a = 1, b = 2) and its values compared as specified. So on to the next rounds of iteration in which we pass `[3, 4]` and `[5, 6]` one by one. This happens because the block `{|a, b| if a + b > 10 }` is treated as a non-lambda proc. This property is not limited to `#select` but also applies to other `enum` methods like `#map`, `#each` etc. -You can read more about this here: [documentation](https://docs.ruby-lang.org/en/3.3/Proc.html) +You can read more about this in the [Proc class documentation](https://docs.ruby-lang.org/en/3.3/Proc.html). A lambda, on the other hand, DOES care and will raise an error if you don't honor the number of parameters expected. @@ -452,9 +452,9 @@ arr.map(&:to_i) # => [1, 2, 3] ``` -What happens under the hood is that `#to_proc` is called on the symbol `:to_i`. You can see what it does in the [ruby docs](https://docs.ruby-lang.org/en/3.3/Symbol.html#method-i-to_proc). It returns a proc object which responds to the given method indicated by the symbol. So here, `#map` yields each value in the array to the proc object, which calls `#to_i` on it. +What happens under the hood is that `#to_proc` is called on the symbol `:to_i`. You can see [what #to_proc does](https://docs.ruby-lang.org/en/3.3/Symbol.html#method-i-to_proc) in the Ruby docs. It returns a proc object which responds to the given method indicated by the symbol. So here, `#map` yields each value in the array to the proc object, which calls `#to_i` on it. -(Yes, names of methods like `#to_i` can be passed around using symbols. It's outside the scope of this lesson, but check out the [documentation](https://docs.ruby-lang.org/en/3.3/Object.html#method-i-send) for `#send` if you're interested. And this Stack Overflow [article](https://stackoverflow.com/questions/14881125/what-does-to-proc-method-mean) on how `#send` and `#to_i` are used together for `arr.map(&:to_i)` to work.) +(Yes, names of methods like `#to_i` can be passed around using symbols. It's outside the scope of this lesson, but check out the [documentation for #send](https://docs.ruby-lang.org/en/3.3/Object.html#method-i-send) if you're interested, and this Stack Overflow article on [how #send and #to_i are used together](https://stackoverflow.com/questions/14881125/what-does-to-proc-method-mean) for `arr.map(&:to_i)` to work.) The `&` also works the other way. You can prepend it to a proc object and it converts it to a block, and passes the block to the method being called. @@ -492,15 +492,17 @@ Blocks are used everywhere in Ruby. You'll find many use cases, and see them use After coming to grips with the information in this lesson you'll be a block, proc and lambda master, able to easily craft beautiful Ruby code. ### Assignment +
-1. [This article](https://www.rubyguides.com/2016/02/ruby-procs-and-lambdas/) provides quite a nice summary of much of what we've covered here. -2. Read [this article](https://www.honeybadger.io/blog/using-lambdas-in-ruby/) which also covers much of what we've used here. We really liked the small section on using lambdas as computed hashes and arrays. A cool use case. +1. This article provides quite a nice [summary of blocks, procs and lambdas](https://www.rubyguides.com/2016/02/ruby-procs-and-lambdas/). +1. Read this [article on lambdas in Ruby](https://www.honeybadger.io/blog/using-lambdas-in-ruby/) which also covers much of what we’ve used here. We really liked the small section on using lambdas as computed hashes and arrays. A cool use case. +
### Knowledge check -This section contains questions for you to check your understanding of this lesson. If you're having trouble answering the questions below on your own, review the material above to find the answer. +The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. - [What is a block?](https://www.rubyguides.com/2016/02/ruby-procs-and-lambdas/#Understanding_Ruby_Blocks) - [How is a block like a method?](https://www.rubyguides.com/2016/02/ruby-procs-and-lambdas/#Understanding_Ruby_Blocks) diff --git a/ruby/advanced_ruby/pattern_matching.md b/ruby/advanced_ruby/pattern_matching.md index 71adb84a847..14d2506dc97 100644 --- a/ruby/advanced_ruby/pattern_matching.md +++ b/ruby/advanced_ruby/pattern_matching.md @@ -76,18 +76,18 @@ The case/in format is best used when there are multiple conditionals you could p There are multiple ways of potentially matching against an input. Patterns can be: - - Any Ruby object which is matched using `===`. The Object Pattern. - - A variable capture / Variable Pattern - - An As Pattern - - An Alternative Pattern - - A Guard Condition - - An Array Pattern - - A Hash Pattern +- Any Ruby object which is matched using `===`. The Object Pattern. +- A variable capture / Variable Pattern +- An As Pattern +- An Alternative Pattern +- A Guard Condition +- An Array Pattern +- A Hash Pattern You can use the above patterns while also having the following experimental additions. - - Rightward Assignment - - A Find Pattern +- Rightward Assignment +- A Find Pattern Patterns can also be matched using many of the patterns above together. For example, you may have an array inside a hash, so you could use the hash and array patterns. We'll go through each of the various patterns in more detail below. @@ -95,7 +95,7 @@ When we say "pattern", we aren't talking about design patterns which you may hav ### Return values -There are two possible outcomes for a pattern match statement - either there is a match or there is no match. If there is a match, it will return the last evaluated value in the body of the matching branch. +There are two possible outcomes for a pattern match statement - either there is a match or there is no match. If there is a match, it will return the last evaluated value in the body of the matching branch. If there are no matches, the pattern matching statement will return `NoMatchingPatternError`. Consider the following example, where the variable `result` is assigned the value 3. @@ -113,9 +113,9 @@ puts result #=> 3 ``` -When we `puts` something inside a case statement, we'll use `#=>` to show what `puts` will print. -In your terminal, however, you'll see the value printed followed by `=> nil`, since `puts` returns `nil`. -We'll omit that because it's not relevant to what we're trying to show you. +When we `puts` something inside a case statement, we'll use `#=>` to show what `puts` will print. +In your terminal, however, you'll see the value printed followed by `=> nil`, since `puts` returns `nil`. +We'll omit that because it's not relevant to what we're trying to show you. Just be aware that the `nil` you see is just the return value of `puts`. Standard Ruby behaviour. As you'll see, though, the point of a pattern match usually is to not only match against a pattern, but also bind all or part of the match to one or more variables that you can then use outside of the pattern match expression. @@ -143,16 +143,16 @@ It's important to note here that Ruby places the pattern to match on the left of With Ruby pattern matching, you can match against the following literal types. - - Booleans - - nil - - Numbers - - Strings - - Symbols - - Arrays - - Hashes - - Ranges - - Regular Expressions - - Procs +- Booleans +- nil +- Numbers +- Strings +- Symbols +- Arrays +- Hashes +- Ranges +- Regular Expressions +- Procs This isn't any different from what we can do with a case/when statement, but the power comes when you match these types within some of the other patterns as we'll see next. @@ -666,22 +666,25 @@ With pattern matching, we do need to consider the case if there is no match. Wit Pattern Matching provides a powerful way to get at the data you need in a way that makes sense. But as with any tool, you don't need to reach for it in every use case. For data structures that are shallow, just think about whether you need to bring in a pattern match when you could just grab the value using the hash and array methods already available. If you do find yourself deep in a nested structure with many checks for `nil` and a lot of edge case handling, it might be time to see if pattern matching brings something to the table. ### Assignment +
-1. Read the [Ruby docs](https://docs.ruby-lang.org/en/3.3/syntax/pattern_matching_rdoc.html) on pattern matching. They cover quite a lot of ground. +1. Read the [Ruby docs on pattern matching](https://docs.ruby-lang.org/en/3.3/syntax/pattern_matching_rdoc.html). They cover quite a lot of ground. +
### Knowledge check -This section contains questions for you to check your understanding of this lesson. If you're having trouble answering the questions below on your own, review the material above to find the answer. -- What is pattern matching? -- What is the difference between array patterns and hash patterns? -- What is the variable pattern match? -- What are the different ways of pattern matching on an array? -- Explain the find pattern. +The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge. + +- [What is pattern matching?](https://docs.ruby-lang.org/en/3.3/syntax/pattern_matching_rdoc.html) +- [What is the difference between array patterns and hash patterns?](https://docs.ruby-lang.org/en/3.3/syntax/pattern_matching_rdoc.html#label-Patterns) +- [What is the variable pattern match?](#variable-pattern) +- [What are the different ways of pattern matching on an array?](#array-pattern-match) +- [Explain the find pattern.](#find-pattern) ### Additional resources -This section contains helpful links to related content. It isn’t required, so consider it supplemental. +This section contains helpful links to related content. It isn't required, so consider it supplemental. - [An Introduction to Pattern Matching in Ruby](https://blog.appsignal.com/2021/07/28/introduction-to-pattern-matching-in-ruby.html) from AppSignal should be another useful perspective on the material. diff --git a/ruby/advanced_ruby/project_custom_enumerables.md b/ruby/advanced_ruby/project_custom_enumerables.md index 452f19472aa..27d09bc68f0 100644 --- a/ruby/advanced_ruby/project_custom_enumerables.md +++ b/ruby/advanced_ruby/project_custom_enumerables.md @@ -42,7 +42,7 @@ If the block returns `true`/truthy for an element, we immediately `return` that
1. Fork and clone our [custom enumerables repo](https://github.com/TheOdinProject/custom_enumerable_project) -1. Follow the [instructions in the README](https://github.com/TheOdinProject/custom_enumerable_project#installation) to get the repo setup locally +1. Follow the [installation instructions in the README](https://github.com/TheOdinProject/custom_enumerable_project#installation) to get the repo setup locally. 1. Rebuild each of [the methods in the table at the end of the README](https://github.com/TheOdinProject/custom_enumerable_project#methods) and make sure they all pass the tests associated with them.