-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
names = ["Foo", "Bar"] | ||
puts names.first # Foo | ||
puts names[0] # Foo | ||
|
||
names = [] of String | ||
# puts names.first | ||
# Unhandled exception: Empty enumerable (Enumerable::EmptyError) | ||
|
||
# puts names[0] | ||
# Unhandled exception: Index out of bounds (IndexError) | ||
|
||
first = names.first? | ||
puts first.nil? # true | ||
first = names[0]? | ||
puts first.nil? # true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
planets = { | ||
"Mars" => 1, | ||
"Jupyter" => 2, | ||
"Saturn" => 3, | ||
"Earth" => 4, | ||
} | ||
puts planets.clear # {} | ||
puts planets # {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
planets = { | ||
"Mars" => 1, | ||
"Jupyter" => 2, | ||
"Saturn" => 3, | ||
"Earth" => 4, | ||
} | ||
puts planets.delete("Mars") | ||
puts planets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | ||
{"Jupyter" => 2, "Saturn" => 3, "Earth" => 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
planets = { | ||
"Mars" => { | ||
"Traveler" => "Elon", | ||
"People" => "Green", | ||
}, | ||
"Jupyter" => 2, | ||
"Saturn" => 3, | ||
"Earth" => 4, | ||
} | ||
# puts planets["Mars"]["People"] | ||
# Error: undefined method '[]' for Int32 (compile-time type is (Hash(String, String) | Int32)) | ||
|
||
puts planets.dig "Mars", "People" # Green | ||
|
||
# puts planets.dig "Mars", "Date" | ||
# Unhandled exception: Missing hash key: "Date" (KeyError) | ||
|
||
date = puts planets.dig? "Mars", "Date" # nil | ||
puts date.nil? # true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
planets = { | ||
"Mars" => { | ||
"color" => "Red, brown and tan.", | ||
}, | ||
"Jupyter" => { | ||
"color" => "Brown, orange and tan, with white cloud stripes.", | ||
}, | ||
"Saturn" => { | ||
"color" => "Golden, brown, and blue-grey.", | ||
}, | ||
"Earth" => { | ||
"color" => "Blue, brown green and white.", | ||
}, | ||
} | ||
|
||
puts planets["Mars"]["color"] | ||
|
||
# puts planets["Mercury"] | ||
# Unhandled exception: Missing hash key: "Mercury" (KeyError) | ||
|
||
# puts planets["Mars"]["rover"] | ||
# Unhandled exception: Missing hash key: "rover" (KeyError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
planets = { | ||
"Mars" => 1, | ||
"Jupyter" => 2, | ||
"Saturn" => 3, | ||
"Earth" => 4, | ||
} | ||
puts planets.reject("Mars") | ||
puts planets | ||
|
||
puts planets.reject!("Mars") | ||
puts planets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"Jupyter" => 2, "Saturn" => 3, "Earth" => 4} | ||
{"Mars" => 1, "Jupyter" => 2, "Saturn" => 3, "Earth" => 4} | ||
{"Jupyter" => 2, "Saturn" => 3, "Earth" => 4} | ||
{"Jupyter" => 2, "Saturn" => 3, "Earth" => 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
planets = { | ||
"Mars" => 1, | ||
"Jupyter" => 2, | ||
"Saturn" => 3, | ||
"Earth" => 4, | ||
} | ||
|
||
puts planets.select { |name, number| number > 2 && name.includes?("r") } | ||
puts planets | ||
|
||
puts planets.select! { |name, number| number > 2 && name.includes?("r") } | ||
puts planets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"Saturn" => 3, "Earth" => 4} | ||
{"Mars" => 1, "Jupyter" => 2, "Saturn" => 3, "Earth" => 4} | ||
{"Saturn" => 3, "Earth" => 4} | ||
{"Saturn" => 3, "Earth" => 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters