I was going through some of the concepts on the Ruby track to revisit what I’ve learned a while back and I noticed that the contents of concepts/nil/about.md is exactly the same as concepts/instance-variables/about.md. This is very likely a bug.
I am getting this diff for those two files:
26,27c26,27
< - Methods named with a trailing `=` are recognized as setters by Ruby, and allow the optional use of the assignment syntax, e.g. `Backpack.new("Sven").owner = "Ayah"`
< - Getters and setters can be shortened using the `attr_reader`, `attr_writer`, and `attr_accessor` methods:
---
> - Methods named with a trailing `=` are recognized as setters by Ruby, and allow the syntactic "sugar" use of the assignment syntax, e.g. `Backpack.new("Sven").owner = "Ayah"`. Notice the space between `owner` and `=` while the actual method name is `owner=`.
> - Getters and setters can be created using the `attr_reader`, `attr_writer`, and `attr_accessor` methods:
43c43
< - If there was a typographical error (we call this "typo") in the previous example (e.g. `@ownar`), it would silently be assigned `nil`, potentially introducing a bug into the system.
---
> - If there was a typographical error (we call these "typo") in the previous example (e.g. `@ownar`), it would fail silently, potentially introducing a bug into the system.
Is this correct, or am I mistaken?
Hmm I didn’t bother checking the diff, I noticed it when reading through the concepts on the website. Still, to me it looks like the “Nil” concept is not actually talking about Nil at all, except for maybe mentioning it once in the context of an attribute setter. This seems like a copy-paste error.
I am pretty sure it was not in error. Someone probably wanted to use it as a template.
The first diff seems to talk about what happens when you create an attribute reader, or even an attribute writer. The instance variable that it represents, and that is assigned to, regardless if called, will have already set the instance variable to nil
. And so that is appropriate for the concept.
The second diff is surely about behavior related to this, and the typographical error response concerning instance variables being directly used is not as good as having a typographical error regarding a method call, which instead will raise an exception where the mistake happened.
Do you have a patch that you would like to see for this?
OK so I would expect the “about” page for the Nil concept (which is visible after a student completes the corresponding concept exercise) explain at least:
- What
nil
represents in Ruby - How (and or when) to check if something is
nil
- What happens when you try to access a field/method on something that is
nil
I am not sure what needs to go in there exactly as I am not a Ruby programmer. In fact, that is why I was reading the concepts again. I completed the exercises a while ago and I was looking for a refresher, and in its current state the page didn’t help me understand the Nil concept much better.
Did you see this information?
# Introduction
[Nil][nil-dictionary] is an English word meaning "nothing" or "zero". In Ruby, `nil` is used to express the _absence_ of an object. In other programming languages, `null` or `none` values may play a similar role.
```ruby
# I do not have a favorite color
favorite_color = nil
```
Ruby gives any instance variable the default value of `nil` when it is first encountered, until it is set otherwise.
[nil-dictionary]: https://www.merriam-webster.com/dictionary/nil
I agree with you that the reading for the concept spends too much time on initialize
and new
rather than really teaching about nil
.
I fixed it: Fix copy and pasted nil about.md by iHiD · Pull Request #1585 · exercism/ruby · GitHub
Thanks for reporting.