-
-
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
161 changed files
with
712 additions
and
805 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
x = 23 | ||
y = 19 | ||
z = x + y | ||
puts z # 42 | ||
puts "#{x} + #{y} is #{z}" # 23 + 19 is 42 | ||
puts z # 42 | ||
puts "#{x} + #{y} is #{z}" # 23 + 19 is 42 | ||
|
||
a = "23" | ||
b = "19" | ||
c = a + b | ||
puts c # 2319 | ||
puts "#{a} + #{b} is #{c}" # 23 + 19 is 2319 | ||
puts c # 2319 | ||
puts "#{a} + #{b} is #{c}" # 23 + 19 is 2319 |
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
planets = ["Mars", "Jupyter", "Saturn", "Earth"] | ||
p! planets # ["Mars", "Jupyter", "Saturn", "Earth"] | ||
puts typeof(planets) # Array(String) | ||
puts planets.size # 4 | ||
p! planets # ["Mars", "Jupyter", "Saturn", "Earth"] | ||
puts typeof(planets) # Array(String) | ||
puts planets.size # 4 | ||
|
||
integers = [3, 8, -2] | ||
puts typeof(integers) # Array(Int32) | ||
puts typeof(integers) # Array(Int32) | ||
|
||
floats = [3.14, 2.1] | ||
puts typeof(floats) # Array(Float64) | ||
puts typeof(floats) # Array(Float64) | ||
|
||
mixed = [1, 3.14, "PI"] | ||
puts typeof(mixed) # Array(Float64 | Int32 | String) | ||
|
||
puts typeof(mixed) # Array(Float64 | Int32 | String) |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
planets = ["Mars", "Jupyter", "Saturn", "Earth"] | ||
|
||
planets.each {|planet| puts planet} | ||
planets.each { |planet| puts planet } | ||
|
||
# enumerate | ||
planets.each_with_index {|planet, idx| | ||
puts "#{idx}: #{planet}" | ||
planets.each_with_index { |planet, idx| | ||
puts "#{idx}: #{planet}" | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
text = "123456789112777" | ||
count = [0] * 10 | ||
|
||
text.each_char {|chr| | ||
count[chr.to_i] += 1 | ||
text.each_char { |chr| | ||
count[chr.to_i] += 1 | ||
} | ||
|
||
count.each_with_index {|value, idx| | ||
puts "#{idx} #{value}" | ||
count.each_with_index { |value, idx| | ||
puts "#{idx} #{value}" | ||
} |
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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
# empty = [] # Syntax error | ||
|
||
|
||
empty = [] of Int32 | ||
puts empty.size # 0 | ||
puts empty.empty? # true | ||
puts empty.size # 0 | ||
puts empty.empty? # true | ||
|
||
empty << 23 | ||
puts empty.size # 1 | ||
puts empty.empty? # false | ||
puts empty.size # 1 | ||
puts empty.empty? # false | ||
|
||
# empty << 3.14 # Error: no overload matches 'Array(Int32)#<<' with type Float64 | ||
|
||
other = Array(Int32).new | ||
puts typeof(other) # Array(Int32) | ||
puts other.size # 0 | ||
|
||
puts typeof(other) # Array(Int32) | ||
puts other.size # 0 |
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
numbers = [10, 20, 7, 21, 5] | ||
puts numbers | ||
small = numbers.reject do |num| num > 10 end | ||
small = numbers.reject do |num| | ||
num > 10 | ||
end | ||
puts small | ||
|
||
big = numbers.reject! do |num| num < 10 end | ||
big = numbers.reject! do |num| | ||
num < 10 | ||
end | ||
puts big |
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 |
---|---|---|
|
@@ -5,4 +5,3 @@ p! typeof(x) | |
x = 1 | ||
p! x | ||
p! typeof(x) | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
result = `ls -l` | ||
if $?.success? | ||
puts result | ||
puts result | ||
else | ||
puts "Failure" | ||
end | ||
puts "Failure" | ||
end |
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
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
if ARGV.size != 1 | ||
puts "Usage: case.cr DIRECTION" | ||
exit -1 | ||
puts "Usage: case.cr DIRECTION" | ||
exit -1 | ||
end | ||
direction = ARGV[0] | ||
|
||
|
||
case direction | ||
when "forward" | ||
puts "go on" | ||
when "bacward" | ||
puts "go back" | ||
when "left", "right" | ||
puts "go #{direction}" | ||
else | ||
puts "We don't know how to go '#{direction}'" | ||
exit 0 | ||
when "forward" | ||
puts "go on" | ||
when "bacward" | ||
puts "go back" | ||
when "left", "right" | ||
puts "go #{direction}" | ||
else | ||
puts "We don't know how to go '#{direction}'" | ||
exit 0 | ||
end |
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 |
---|---|---|
|
@@ -17,4 +17,3 @@ when Int32 | |
puts "int32" | ||
puts x.abs | ||
end | ||
|
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
|
||
filenames = ["README.md", "Other file", "crystal.json"] | ||
filenames.each {|file| | ||
begin | ||
result = process(file) | ||
puts result | ||
rescue err | ||
puts "Rescued! #{err.message}" | ||
puts err.class # File::NotFoundError | ||
end | ||
filenames.each { |file| | ||
begin | ||
result = process(file) | ||
puts result | ||
rescue err | ||
puts "Rescued! #{err.message}" | ||
puts err.class # File::NotFoundError | ||
end | ||
} | ||
|
||
def process(filename) | ||
content = File.read(filename) | ||
return content.size | ||
content = File.read(filename) | ||
return content.size | ||
end |
Oops, something went wrong.