Demo entry 6785689

Union Type

   

Submitted by anonymous on Mar 19, 2019 at 08:28
Language: Crystal. Code size: 241 Bytes.

class Weird
  property val : Int32 | Nil

  def initialize
    @val = nil
  end

  def initialize(@val)
  end

  def add(n : Int32)
    if !@val
      @val = 0
    end
    @val += n
  end
end

a = Weird.new 9
a.add(19)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).