This file contains hidden or 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
| require "file_utils" | |
| ROOT_PATH = Path.home / Path.new("Documents/Layout") | |
| class Layout | |
| getter parentId : Int32? | |
| getter container : Bool | |
| property children : Array(Layout) | |
| def initialize(@id : Int32, @parentId : Int32?, @name : String, @type : String, @container : Bool) |
This file contains hidden or 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
| require 'pp' | |
| def f(a, b, *args, foo: "foo", required:, times: 2, **kwargs) | |
| puts a, b | |
| pp args | |
| puts foo | |
| puts times | |
| pp kwargs | |
| puts required | |
| end |
This file contains hidden or 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
| enum Control | |
| Done | |
| end | |
| class Worker(T) | |
| def initialize | |
| @channel = Channel(T|Control).new(10) | |
| @done = Channel(Control).new |
This file contains hidden or 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
| struct Int32 | |
| def to(t : Int32.class) | |
| self | |
| end | |
| def to(t : Int64.class) | |
| self.to_i64 | |
| end | |
| def to(t : String.class) |
This file contains hidden or 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
| struct Int32 | |
| def to(t : Int32.class) | |
| self | |
| end | |
| def to(t : Int64.class) | |
| self.to_i64 | |
| end | |
| def to(t : String.class) |
This file contains hidden or 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
| struct Int32 | |
| def to(t : Int64.class) | |
| self.to_i64 | |
| end | |
| end | |
| a = 13_i32 | |
| b = a.to(Int64) |
This file contains hidden or 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
| def inner_scope(*args) | |
| return yield(*args) | |
| end | |
| def run : Int32 | |
| # must declare i here to use in this scope | |
| i = inner_scope(3, 2) { |args| | |
| x, y = args | |
| i = x + y | |
| } |
This file contains hidden or 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
| def foo | |
| yield | |
| end | |
| def run : Int32 | |
| # must declare i here to use in this scope | |
| i = nil | |
| foo { | |
| i = 2 | |
| } |
This file contains hidden or 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
| ch = Channel(Nil).new | |
| alias TH = Thread(Nil, Nil) | |
| threads = Array(TH).new | |
| threads << TH.new do | |
| 6.times do | |
| sleep 1 | |
| puts 1 | |
| end | |
| ch.send(nil) | |
| nil |
NewerOlder