If some of my libraries locate out of default directory lib, could I indicate the require path to compile successfully without lib directory nor shards.yml.
I was wondering if I simply cannot find a between method for numbers in Crystal.
In Ruby, there's the Comparable#between? method which can (among others) compare two numeric values (my specific case).
Background: I want to achieve a not-between…
While reading through the Crystal docs, I came across this line:
deq = Deque{2, 3}
So I think this calls the Deque.new(array : Array(T)) constructor. However, I did not find any documentation about this syntax whatsoever.
(EDIT: The documentation…
Coming from the Ruby world, I instantly understood why Crystal chose not to implement a for method. But then I was surprised to see that Crystal does implement a for method for macros. I was even more surprised to find that macros don't allow an…
In JSON.mapping documentation explicitly stated the value of type property should be single type. However, in practice union types also works:
json1 = %q({"ok": true, "result": [{"type": "update", "id": 1}, {"type": "update", "id": 2}]})
json2 =…
How to map parsed JSON as JSON::Any type to custom Object?
In my case, I am working on chat client. Chat API can respond to requests with following JSON:
{"ok" => true,
"result" =>
[{"update_id" => 71058322,
"message" =>
{"message_id" =>…
I am trying to learn to debug programs written in Crystal with GDB. Here is a sample:
class Demo
@array = [] of String
def bar(url)
ret = url.downcase * 2
if ret == "alsj"
return false
else
return ret
end
end
…
Suppose I've got a simple JSON mapped object in Crystal lang, e.g.:
class Item
JSON.mapping(
id: UInt32,
name: String,
)
end
I can parse individual objects from JSON strings easily like so:
foo =…
If a developer compiles a Crystal program, what metadata will the binary file store and how to remove any sensitive information? By sensitive I mean device identificators, local IP addresses or anything else.
I'm new to Crystal. I'd like to try and find the SHA256 hash of a hex string. I've managed to get something working:
sha256 = OpenSSL::Digest.new("sha256")
puts sha256.update("abcd")
But I'm not sure how to put the binary value of "abcd" in to the…
I am trying to bind some functions from glib into Crystal. I've done this and it works:
@[Link("glib-2.0")]
lib LibG
fun g_utf8_strup(str : UInt8*, len : UInt32) : UInt8*
fun g_utf8_strdown(str : UInt8*, len : UInt32) : UInt8*
end
However it…
I have an array of UInt32, what is the most efficient way to write it into a binary file in Crystal lang?
By now I am using IO#write_byte(byte : UInt8) method, but I believe there should be a way to write bigger chunks, than per 1 byte.
As the title states, I'd like to know the proper way to check if an iterator is complete.
I couldn't find anything in the docs but I found something like this in the source:
iter.next.is_a? Iterator::Stop
Toy example:
a = "a世c"
b =…
If I have a file that's meant to be required by other files, is it possible to get the absolute filepath of the file that's requiring it?
So if lib_file.cr has a macro that is meant to be called by the app_file.cr that imported it, can that macro…