Skip to content

Commit

Permalink
Changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed Aug 17, 2024
1 parent f950f39 commit 2ae5744
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions concepts/getters-setters/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "Crystal has macros for defining getters and setters. Which is used to access and modify the instance variables of a class.",
"blurb": "Crystal has macros for defining getters and setters. These are used to access and modify the instance variables of a class.",
"authors": ["meatball133"],
"contributors": []
"contributors": ["ryanplusplus"]
}
4 changes: 2 additions & 2 deletions concepts/getters-setters/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Crystal has defined these as `getter`, `setter` and `property` macros.
Getter is a macro that defines a method that returns the value of an instance variable.
This means that you no longer have to write `@` in front of the instance variable when you want to access it (in methods, excluding initialize); instead, you can call the method that the getter macro has defined.

The getter macro can accept multiple instance variables by separating them with a comma.
The getter macro can accept multiple instance variables by separating them with commas.

```crystal
# This:
Expand Down Expand Up @@ -44,7 +44,7 @@ Symbols will be covered later in the symbol concept.

## Setters

Setters is a macro that defines a method that sets the value of an instance variable.
Setter is a macro that defines a method that sets the value of an instance variable.
This macro isn't that often found and is commonly the `property` macro used instead.
The methods that will be created will look like `name_of_method=`; the `=` is what makes it so the property can be set.

Expand Down
4 changes: 2 additions & 2 deletions concepts/getters-setters/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Crystal has defined these as `getter`, `setter` and `property` macros.
Getter is a macro that defines a method that returns the value of an instance variable.
This means that you no longer have to write `@` in front of the instance variable when you want to access it (in methods, excluding initialize); instead, you can call the method that the getter macro has defined.

The getter macro can accept multiple instance variables by separating them with a comma.
The getter macro can accept multiple instance variables by separating them with commas.

```crystal
# This:
Expand Down Expand Up @@ -44,7 +44,7 @@ Symbols will be covered later in the symbol concept.

## Setters

Setters is a macro that defines a method that sets the value of an instance variable.
Setter is a macro that defines a method that sets the value of an instance variable.
This macro isn't that often found and is commonly the `property` macro used instead.
The methods that will be created will look like `name_of_method=`; the `=` is what makes it so the property can be set.

Expand Down
5 changes: 0 additions & 5 deletions exercises/concept/task-handler/.docs/test.cr

This file was deleted.

4 changes: 2 additions & 2 deletions exercises/concept/weighing-machine/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## General

- To creat the getter and setter methods you should use the `getter`, `setter` and `property` macros.
- To create the getter and setter methods you should use the `getter`, `setter` and `property` macros.

## 1. Create an initial state for the weighing machine

- To initialize the weighing machine you should use the `initialize` method.
- The method should take two arguments, `precision` and `metric` which should be a `Int32` and `Bool` respectively.
- The method should take two arguments, `precision` and `metric`, which should be an `Int32` and `Bool`, respectively.
These should be used to set the instance variables `@precision` and `@metric`.
- The instance variable `@weight` should be set to `0.0`.

Expand Down
9 changes: 5 additions & 4 deletions exercises/concept/weighing-machine/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Instructions

In this exercise you'll be modelling a weighing machine.
In this exercise you'll be modeling a weighing machine.

## 1. Create an initial state for the weighing machine

The weighing machine when initalized should refer to its factory settings which is different for where the machine is sold.
When initialized, the weighing machine should refer to its factory settings which is different for where the machine is sold.
Thereby the machine should be able to be initialized with a precision and if it is metric or imperial.

Implement the `WeighingMachine#initialize` method which takes two arguments, `precision` which is an `Int32` and `metric` which is a `Bool`.
The `metric` argument when `true` means that the machine should use the metric system, otherwise it should use the imperial system.
The initizalized set should also set an instance variable, `@weight` to `0.0`.
The initialize method set should also set the instance variable `@weight` to `0.0`.

```crystal
precision = 3
Expand Down Expand Up @@ -49,7 +49,8 @@ wm.weigh

## 4. Allow the machine to be switch between metric and imperial units

Implement the `WeighingMachine#metric=` property to allow the unit to be set, it should accept a boolean value.
Implement the `WeighingMachine#metric=` property to allow the unit to be set.
It should accept a boolean value.

```crystal
precision = 3
Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/weighing-machine/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Crystal has defined these as `getter`, `setter` and `property` macros.
Getter is a macro that defines a method that returns the value of an instance variable.
This means that you no longer have to write `@` in front of the instance variable when you want to access it (in methods, excluding initialize); instead, you can call the method that the getter macro has defined.

The getter macro can accept multiple instance variables by separating them with a comma.
The getter macro can accept multiple instance variables by separating them with commas.

```crystal
# This:
Expand Down Expand Up @@ -44,7 +44,7 @@ Symbols will be covered later in the symbol concept.

## Setters

Setters is a macro that defines a method that sets the value of an instance variable.
Setter is a macro that defines a method that sets the value of an instance variable.
This macro isn't that often found and is commonly the `property` macro used instead.
The methods that will be created will look like `name_of_method=`; the `=` is what makes it so the property can be set.

Expand Down
1 change: 1 addition & 0 deletions exercises/concept/weighing-machine/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"authors": ["meatball133"],
"contributors": "ryanplusplus",
"files": {
"solution": [
"src/weighing_machine.cr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe WeighingMachine do
weighing_machine.precision.should eq(5)
end

it "should not allowed to be modify" do
it "should not allow modification" do
{% if WeighingMachine.has_method? "precision=" %}
raise "Error: precision should not have a setter"
{% end %}
Expand Down Expand Up @@ -87,7 +87,7 @@ describe WeighingMachine do
weighing_machine.weigh.should eq("11.023")
end

it "should not allowed to be get" do
it "should not allow getting" do
{% if WeighingMachine.has_method? "metric" %}
raise "Error: metric should not have a getter"
{% end %}
Expand Down

0 comments on commit 2ae5744

Please sign in to comment.