Skip to content

annotation Athena::Serializer::Annotations::VirtualProperty #

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.