How do I declare an array of Strings in a getter / method declaration ?
Ex ( none of these exemples works ) :
class Test
getter var1 : String[]
getter var2 : String*
getter var3 : Array(String)
end
Seem to be having issues with a type mismatch, but I can't wrap my head around it, need a second pair of eyes, I find the Crystal type mismatch errors to be almost unreadable when dealing with databases.
Aliases (accounts.cr)
alias CampaignDetail =…
I'm trying to hash + salt user passwords with the Bcrypt library that ships with Crystal.
The following code produces an "Invalid salt size" error, when run in a playground.
require "crypto/bcrypt"
user = "Jones"
pass = "password"
temp =…
I keep running into this crystal compiler bug and I currently see no workaround other than rebooting my box. I filed an issue here.
crystal$ crystal build main.cr
Unhandled exception in spawn:
fork: Cannot allocate memory (Errno)
0x55b5be: ??? at…
So I have a JSON file of a somewhat known format { String => JSON::Type, ... }. So it is basically of type Hash(String, JSON::Type). But when I try and read it from file to memory like so: JSON.parse(File.read(@cache_file)).as(Hash(String,…
I was expecting that typeof(...) would give me the exact class, but when rescuing an Exception typeof(MyCustomException) just returns Exception
class A < Exception; end
class B < A; end
begin
raise B.new
rescue e
puts typeof(e) # =>…
I have both Go and Crystal installed on macOS.
GOPATH Directory: export PATH=$PATH:/usr/local/go/bin
Crystal Location: /usr/local/bin/crystal
When I initialize a crystal app with crystal init app fizzbuzz (example) in the terminal, the fizzbuzz.cr…
I wish to call the various functions defined in a Rust dylib using Crystal. I've gone through the manual, but I was not able to understand it. How do I properly include and call this dylib? Am I using the CLI flags wrong?
Here's the Crystal…
I'm creating app in crystal-lang with kemal the web framework.
How can I use style.css or Bootstrap files in the app template in kemal?
myapp.cr location = src/myapp.cr
bootstrap located = src/public/css/bootstrap.css
layout file =…
I'm working with the crt.cr Crystal shard, which binds ncurses. It's lacking some things I want, like mvhline(). So I'm adding the things I want.
One thing I want is is ncurses alternative character sheet, so I can make nice boxes.
As far as I can…
I'm trying to get an audio player working with Crystal. The internet indicated that portaudio was the best C library for playing audio, and seeing as there are no native Crystal libraries, it seems like the best option.
Someone already put in most…
So I've got the following code causing issues:
if File.file?(indexPath)
puts "Have to move index"
File.rename(indexPath, "#{indexPath}.old")
end
File.new(indexPath)
File.write(indexPath, "test" )#handler.getDoc)
sleep 60.second
I would…
I'm trying to learn Crystal. As an exercise, I'm making a simple web application, which needs to serve a file (called index.html).
Unfortunately, I can only figure out how to serve the directory the file resides in. This is hat you get if you load…
In my code I open DB at start of program and pass db variable to other methods. I think it's stupid and not right. But what should I do? Should I open db connection in each method? But this way also doesn't look right... And I have a lot of errors:…
On ruby I can do
require "stringio"
def with_captured_stdout
begin
old_stdout = $stdout
$stdout = StringIO.new('','w')
yield
$stdout.string
ensure
$stdout = old_stdout
end
end
and later call it like
str =…