Use bare double underscores instead of atoms
This commit is contained in:
@@ -7,34 +7,34 @@ defmodule Structs do
|
||||
|
||||
koan "Structs are defined and named after a module" do
|
||||
person = %Person{}
|
||||
assert person == :__
|
||||
assert person == __
|
||||
end
|
||||
|
||||
koan "You can access the fields of a struct" do
|
||||
nobody = %Person{}
|
||||
assert nobody.age == :__
|
||||
assert nobody.age == __
|
||||
end
|
||||
|
||||
koan "You can pass initial values to structs" do
|
||||
joe = %Person{name: "Joe", age: 23}
|
||||
assert joe.name == :__
|
||||
assert joe.name == __
|
||||
end
|
||||
|
||||
koan "Update fields with the pipe '|' operator" do
|
||||
joe = %Person{name: "Joe", age: 23}
|
||||
older = %{ joe | age: joe.age + 10}
|
||||
assert older.age == :__
|
||||
assert older.age == __
|
||||
end
|
||||
|
||||
koan "The original struct is not affected by updates" do
|
||||
joe = %Person{name: "Joe", age: 23}
|
||||
assert %{ joe | age: joe.age + 10}.age == :__
|
||||
assert joe.age == :__
|
||||
assert %{ joe | age: joe.age + 10}.age == __
|
||||
assert joe.age == __
|
||||
end
|
||||
|
||||
koan "You can pattern match into the fields of a struct" do
|
||||
%Person{age: age} = %Person{age: 22, name: "Silvia"}
|
||||
assert age == :__
|
||||
assert age == __
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
@@ -45,14 +45,14 @@ defmodule Structs do
|
||||
def plane?(_), do: false
|
||||
|
||||
koan "Or onto the type of the struct itself" do
|
||||
assert plane?(%Plane{passengers: 417, maker: :boeing}) == :__
|
||||
assert plane?(%Person{}) == :__
|
||||
assert plane?(%Plane{passengers: 417, maker: :boeing}) == __
|
||||
assert plane?(%Person{}) == __
|
||||
end
|
||||
|
||||
|
||||
koan "Are basically maps" do
|
||||
silvia = %Person{age: 22, name: "Silvia"}
|
||||
|
||||
assert Map.fetch!(silvia, :age) == :__
|
||||
assert Map.fetch!(silvia, :age) == __
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user