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
test |
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
3.0 / 2.0 | |
3.0 // 2.0 | |
3.0 / 2 | |
3.0 // 2 | |
3 / 2 | |
3 // 2 | |
3 / 2.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
if true | |
a = 10 | |
else | |
b = 20 | |
end | |
p a #=> 10 | |
p b #=> nil |
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
# crystal | |
str1 = " | |
if true | |
10 | |
else | |
20 | |
end | |
" | |
str2 = <<-STR |
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
# crystal | |
a = <<-INPUT | |
10 | |
INPUT #=> syntax ok | |
b = { | |
<<-INPUT | |
10 | |
INPUT, 10 | |
} #=> syntax error |
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
# crystal | |
## string is immutable | |
str = "" | |
str.object_id #=> 94763530681144_u64 | |
str += "abc" | |
str.object_id #=> 94494250273768_u64 |
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
alias A = Int32 -> Int32 | |
A.new do |x| | |
return x | |
end #=> Proc(Int32, Int32) |
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
# crystal | |
def a(*args : Int32) | |
args | |
end | |
a(1, 2) #=> {1, 2} | |
a(1) #=> {1} | |
def b(a, b) | |
a + b |
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
# crystal | |
arr = [1, 2, 3, 4, 5] | |
arr[1..-1] #=> [2, 3, 4, 5] | |
arr[1...-1] #=> [2, 3, 4] | |
arr[-2..-1] #=> [4, 5] | |
(1..2).includes?(2) #=> true | |
(1...2).includes?(2) #=> false |
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
# crystal | |
{"a" => 1, "b" => 2} #=> {"a" => 1, "b" => 2} : Hash(String, Int32) | |
a = {"a": 1, "b": 2} #=> {a: 1, b: 2} : NamedTuple(a: Int32, b: Int32) | |
{"a" => 1, "b": 2} #=> {"a" => 1, "b" => 2} | |
{"a": 1, "b" => 2} #=> Syntax error in :6: space not allowed between named argument name and ':' | |
OlderNewer