Skip to content
GitHub Repository Forum RSS-Newsfeed

Crystal 0.20.1 released!

Johannes Müller

Crystal 0.20.1 has been released!

As any release it includes numerous bugfixes, cool features and performance improvements - in 75 commits since 0.20.0.

Exciting Changes

  • p and pp now use pretty printing.
  • finished macro hook was added. It places it’s contents at the end of the program when all other types and methods are known.
class MyModel
  MAPPING = {
    id: Int32
  }

  macro extra_attributes(**values){% for key, value in values %}{% MAPPING[key] = value %}{% end %}
  end

  macro finished
    JSON.mapping({{MAPPING}})
  end
end

class MyModel
  extra_attributes name: String, foo: Bool
end

# JSON mapping will have attribute id, name and foo.
  • Local variables can now have type restrictions.
  • method_missing hook can now define a method, this allows it to control whether it captures a block (see PR #3610)
class Foo
  def add(method, &block : -> U) forall U
    puts "added #{method} #{block}"
  end

  macro method_missing(call)
    def {{call.name}}(&block : -> U) forall U
      add({{call.name.stringify}}, &block)
    end
  end
end

Foo.new.foo { 1 } # => added foo #<Proc(Int32):0x1063173a0>
Foo.new.bar { 2 } # => added bar #<Proc(Int32):0x1063173b0>

Other Breaking Changes

  • (breaking change) Set#merge as renamed to Set#merge!
  • (breaking change) Slice.new(size) no longer works with non primitive integers and floats
  • (breaking change) The macro method argify was renamed to splat

Thanks to everyone who supported this release through contributions, reviews and suggestions.