View generics-inheritance-error.cr
module Core
end
class Base(T)
include Core
end
class Foo < Base(String)
end
View 1.value-and-exception.cr
def parse(str)
JSON.parse(str)
end
pp parse("1") # => 1
pp parse("x") # raise JSON::ParseException
begin
v = parse("1")
# use v
View generics-problem-min.cr
module Core(T)
@a : Bool
end
class Base(T)
include Core(Int32)
def initialize
@a = true
end
View test.cr
class Changeset(T)
def initialize(@instance : T)
end
end
module Cset(T)
def changeset(instance)
Changeset(T).new(instance)
end
end
View 0.general.sh
#!/usr/bin/env zsh
set -e
# for shards-0.7
rm -rf shard.lock libs
shards update
echo "/lib/" >> .gitignore
# MemoryIO
sed -i "s/MemoryIO/IO::Memory/g" {src,spec}/**/*.cr
View using-crystal_lib.sh
% git clone git@github.com:crystal-lang/crystal_lib.git
% cd crystal_lib
% cat > lib_ntohl.cr
@[Include("arpa/inet.h")]
lib LibC
fun ntohl
end
% crystal src/main.cr -- lib_ntohl.cr
lib LibC
View awalk.cr
alias Entry = Hash(Symbol, File::Stat | String)
def awalkDir(dir, block : Entry -> Nil)
Dir.entries(dir).each do |fname|
next if fname == "." || fname == ".."
current = File.join(dir, fname)
begin