val.cr 
Scala-ish lazy val
, var
for Crystal.
- crystal: 0.20.4
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.
-
getter
with=
evaulates code immediately, butval
runs lazily.
-
getter
with=
fails with multiple lines, butval
accepts it.
Although getter
with block
runs lazily, block format has less readability than =
.
Contributing
- Fork it ( https://github.com/maiha/val.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- maiha maiha - creator, maintainer