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
Int32.new("+1") #=> 1 | |
Int32.new("-1") #=> -1 | |
"+1".to_i #=> 1 | |
"-1".to_i #=> -1 |
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
type_id = 0b0001 | |
flags = [false, true, false, true] | |
(type_id & 0x0F) << 4 | |
((type_id & 0x0F) << 4).to_u8 | | |
(flags[3] ? 0x8_u8 : 0x0_u8) | | |
(flags[2] ? 0x4_u8 : 0x0_u8) | | |
(flags[1] ? 0x2_u8 : 0x0_u8) | | |
(flags[0] ? 0x1_u8 : 0x0_u8) |
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
0xFFFFFFFF | |
0b11111111111111111111111111111111 | |
0xFF_FF_FF_FF | |
0b11111111_11111111_11111111_11111111 |
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 | |
enum Abc : UInt8 | |
A = 0x00 | |
B = 0x01 | |
C = 0x02 | |
end | |
Abc::A + 2 #=> C : Abc |
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
module MyInterface | |
end | |
class MyClass | |
include MyInterface | |
end | |
MyClass.new.is_a?(MyClass) #=> true | |
MyClass.new.is_a?(MyInterface) #=> true | |
[MyClass.new].is_a?(Array(MyClass)) #=> 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
class MyProtocol | |
module MyInterface | |
end | |
def initialize(@clients : Array(MyInterface)) | |
end | |
end | |
class MyClient | |
include MyProtocol::MyInterface |
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 | |
module Interface | |
def a | |
end | |
end | |
class Cls1 | |
include Interface | |
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
# crystal | |
class ABC | |
end | |
def ABC.new | |
false | |
end | |
ABC.new #=> 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, 2, 3] | |
b = [1, 2, 3] | |
a == b #=> true | |
a === b #=> true | |
a = {1, 2, 3} | |
b = {1, 2, 3} | |
a == b #=> true | |
a === b #=> 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
# 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 ':' | |