val.cr Build Status

Scala-ish lazy val, var for Crystal.

dependencies:
  val:
    github: maiha/val.cr
    version: 0.2.0

Usage

require "val"

class Foo
  val x = 1
  var y = "123"
  val z : Int32 = (a = [1]; a << 2; a.sum)

  val cached? = true
end

foo = Foo.new
foo.x         # => 1
foo.y = "xxx" # => "xxx"
foo.z         # => 3
foo.cached?   # => true

NOTE

val is almost same as getter except two points.

Although getter with block runs lazily, block format has less readability than =.

Contributing

  1. Fork it ( https://github.com/maiha/val.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors