annotation Athena::Serializer::Annotations::VirtualProperty

Overview

Can be applied to a method to make it act like a property.

Example

class Example
  include ASR::Serializable

  def initialize; end

  property foo : String = "foo"

  @[ASRA::VirtualProperty]
  @[ASRA::Name(serialize: "testing")]
  def some_method : Bool
    false
  end

  @[ASRA::VirtualProperty]
  def get_val : String
    "VAL"
  end
end

ASR.serializer.serialize Example.new, :json # => {"foo":"foo","testing":false,"get_val":"VAL"}

!!!warning The return type restriction MUST be defined.

Defined in:

annotations.cr