diff --git a/crystal/README.md b/crystal/README.md index ef8ca1786..0ec4a1eaf 100644 --- a/crystal/README.md +++ b/crystal/README.md @@ -34,6 +34,13 @@ filter or grep => reject (use the names other languages use for the same conce What is "flag?" ? I saw it in the source code of Kemal, but I don't see it defined anywhere. +GitHub Actions configurators: https://crystal-lang.github.io/install-crystal/configurator.html + +Yak Shaving + +https://forum.crystal-lang.org/ has around 500 users. +https://gitter.im/crystal-lang/crystal Gitter 1960 people + ### SQLite @@ -41,3 +48,6 @@ Lack of documentation last_id last_insert_id How can one know? puts __FILE__ + + + diff --git a/crystal/examples/assign.cr b/crystal/examples/assign.cr new file mode 100644 index 000000000..1a42e89bd --- /dev/null +++ b/crystal/examples/assign.cr @@ -0,0 +1,3 @@ +a = b = 42 +puts a # 42 +puts b # 42 diff --git a/crystal/examples/constants.cr b/crystal/examples/constants.cr new file mode 100644 index 000000000..a9161941f --- /dev/null +++ b/crystal/examples/constants.cr @@ -0,0 +1,4 @@ +PI = 3.14 + +puts PI +PI = 3.145 # Error: already initialized constant PI diff --git a/crystal/examples/multiple_assignments.cr b/crystal/examples/multiple_assignments.cr new file mode 100644 index 000000000..ccee865c7 --- /dev/null +++ b/crystal/examples/multiple_assignments.cr @@ -0,0 +1,8 @@ +a, b = 2, 3 +puts a # 2 +puts b # 3 + + +a, b = b, a +puts a # 3 +puts b # 2 diff --git a/crystal/other.md b/crystal/other.md index 2923043dc..7f8110531 100644 --- a/crystal/other.md +++ b/crystal/other.md @@ -224,3 +224,39 @@ shards install ![](examples/docspec/src/app.cr) +## require +{id: require} + +{aside} +require - imports are global. This makes it hard to see in a file where some objects might come from +as they might have been required by some other file. + +Similarly requiring a bunch of files in a directory is easy to do, but might make it a bit harder for +someone without an IDE to find the source of each object. +{/aside} + +``` +require "./directory/file" # relative path to the cr file +require "./directory/*" # all the cr files in the directory +require "./directory/**" # all the cr files in the directory - recursively +require "some_name" # Find it somewhere (standard library, src directory) +``` + +* You can put the `require` statements anywhere but you might want to be consistent in your porject. +* Make sure you don't have circular requires. + +## Constants +{id: constants} + +* Variable names that start with upper-case letter are constants + +![](examples/constants.cr) + +## Multiple assignments +{id: multiple-assignments} + +![](examples/multiple_assignments.cr) + +![](examples/assign.cr) + + diff --git a/crystal/spec/todo_spec.cr b/crystal/spec/todo_spec.cr new file mode 100644 index 000000000..8cfc9a933 --- /dev/null +++ b/crystal/spec/todo_spec.cr @@ -0,0 +1,18 @@ +def add(x, y) + return x*y +end + + +describe "test cases" do + it "good" do + add(2, 2).should eq 4 + end + + pending "another test case when the bug is fixed" + it "add" do + add(2, 3).should eq 5 + end + it "add" do + add(2, 4).should eq 6 + end +end diff --git a/crystal/testing.md b/crystal/testing.md index d8c3ec7ad..73a5cb908 100644 --- a/crystal/testing.md +++ b/crystal/testing.md @@ -21,6 +21,8 @@ crystal spec . ![](spec/demo_spec.cr) +![](spec/todo_spec.cr) + ``` crystal spec ```