- README

- Top Level Namespace
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - MD5
    - Context
  - Subtle
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Float
  - Primitive
- Float32
- Float64
- GC
  - Stats
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - DeflateHandler
  - ErrorHandler
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - ArrayBuilder
  - Builder
  - Error
  - Lexer
  - ObjectBuilder
  - ParseException
  - Parser
  - PrettyWriter
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModulePassManager
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- MemoryIO
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
  - X509
    - Certificate
    - Extension
    - Name
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - MT19937
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- XML
  - Attributes
  - AttributeType
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Emitter
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zlib
  - Deflate
  - Error
  - Inflate

# abstract class Class

- Class
- Value
- Object

## Defined in:

## Class Method Summary

- .==(other : Class)
- .===(other)
- .cast(other) : self

  Casts other to this class.

- .clone
- .dup
- .from_json(string_or_io, root : String) : self

  Deserializes the given JSON in string_or_io into an instance of `self`, assuming the JSON consists of an JSON object with key root, and whose value is the value to deserialize.

- .from_json(string_or_io) : self

  Deserializes the given JSON in string_or_io into an instance of `self`.

- .from_yaml(string_or_io) : self
- .hash
- .inspect(io)
- .name : String

  Returns the name of this class.

- .nilable?

  Returns `true` if this class is `Nil`.

- .to_s(io)
- .|(other : U.class) forall U

  Returns the union type of `self` and other.

## Instance Method Summary

- #==(other : Class)
- #===(other)
- #cast(other) : self

  Casts other to this class.

- #clone
- #dup
- #from_json(string_or_io, root : String) : self

  Deserializes the given JSON in string_or_io into an instance of `self`, assuming the JSON consists of an JSON object with key root, and whose value is the value to deserialize.

- #from_json(string_or_io) : self

  Deserializes the given JSON in string_or_io into an instance of `self`.

- #from_yaml(string_or_io) : self
- #hash
- #inspect(io)
- #name : String

  Returns the name of this class.

- #nilable?

  Returns `true` if this class is `Nil`.

- #to_s(io)
- #|(other : U.class) forall U

  Returns the union type of `self` and other.

## Macro Summary

- class_getter(*names)

  Defines getter methods for each of the given arguments.

- class_getter!(*names)

  Defines raise-on-nil and nilable getter methods for each of the given arguments.

- class_getter?(*names)

  Defines query getter methods for each of the given arguments.

- class_property(*names)

  Defines property methods for each of the given arguments.

- class_property!(*names)

  Defines raise-on-nil property methods for each of the given arguments.

- class_property?(*names)

  Defines query property methods for each of the given arguments.

- class_setter(*names)

  Defines setter methods for each of the given arguments.

- def_clone

  Defines a `#clone` method that returns a copy of this object with all instance variables cloned (`#clone` is in turn invoked on them).

- def_equals(*fields)

  Defines an `#==` method by comparing the given fields.

- def_equals_and_hash(*fields)

  Defines `#hash` and `#==` method from the given fields.

- def_hash(*fields)

  Defines a `#hash` method computed from the given fields.

- delegate(*methods, to object)

  Delegate methods to to.

- forward_missing_to(delegate)

  Forwards missing methods to delegate.

- getter(*names)

  Defines getter methods for each of the given arguments.

- getter!(*names)

  Defines raise-on-nil and nilable getter methods for each of the given arguments.

- getter?(*names)

  Defines query getter methods for each of the given arguments.

- property(*names)

  Defines property methods for each of the given arguments.

- property!(*names)

  Defines raise-on-nil property methods for each of the given arguments.

- property?(*names)

  Defines query property methods for each of the given arguments.

- setter(*names)

  Defines setter methods for each of the given arguments.

### Instance methods inherited from struct `Value`

==(other) ==, dup dup

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try

### Class methods inherited from class `Object`

==(other : Class) ==, ===(other) ===, cast(other) : self cast, clone clone, dup dup, from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml, hash hash, inspect(io) inspect, name : String name, nilable? nilable?, to_s(io) to_s, |(other : U.class) forall U |

## Class Method Detail

def self.==(other : Class) #
def self.===(other) #
def self.cast(other) : self #

Casts other to this class.

This is the same as using `as`, but allows the class to be passed around as an argument. See the documentation on as for more information.

    klass = Int32
    number = [99, "str"][0]
    typeof(number)             # => (String | Int32)
    typeof(klass.cast(number)) # => Int32

def self.clone #
def self.dup #
def self.from_json(string_or_io, root : String) : self #

Deserializes the given JSON in string_or_io into an instance of `self`, assuming the JSON consists of an JSON object with key root, and whose value is the value to deserialize.

    Int32.from_json(%({"main": 1}), root: "main") # => 1

def self.from_json(string_or_io) : self #

Deserializes the given JSON in string_or_io into an instance of `self`. This simply creates a `parser = JSON::PullParser` and invokes `new(parser)`: classes that want to provide JSON deserialization must provide an `def initialize(parser : JSON::PullParser` method.

    Int32.from_json("1")                # => 1
    Array(Int32).from_json("[1, 2, 3]") # => [1, 2, 3]

def self.from_yaml(string_or_io) : self #
def self.hash #
def self.inspect(io) #
def self.name : String #

Returns the name of this class.

    String.name # => "String"

def self.nilable? #

Returns `true` if this class is `Nil`.

    Int32.nilable? # => false
    Nil.nilable?   # => true

def self.to_s(io) #
def self.|(other : U.class) forall U #

Returns the union type of `self` and other.

    Int32 | Char # => (Int32 | Char)

## Instance Method Detail

def ==(other : Class) #
def ===(other) #
def cast(other) : self #

Casts other to this class.

This is the same as using `as`, but allows the class to be passed around as an argument. See the documentation on as for more information.

    klass = Int32
    number = [99, "str"][0]
    typeof(number)             # => (String | Int32)
    typeof(klass.cast(number)) # => Int32

def clone #
def dup #
def from_json(string_or_io, root : String) : self #

Deserializes the given JSON in string_or_io into an instance of `self`, assuming the JSON consists of an JSON object with key root, and whose value is the value to deserialize.

    Int32.from_json(%({"main": 1}), root: "main") # => 1

def from_json(string_or_io) : self #

Deserializes the given JSON in string_or_io into an instance of `self`. This simply creates a `parser = JSON::PullParser` and invokes `new(parser)`: classes that want to provide JSON deserialization must provide an `def initialize(parser : JSON::PullParser` method.

    Int32.from_json("1")                # => 1
    Array(Int32).from_json("[1, 2, 3]") # => [1, 2, 3]

def from_yaml(string_or_io) : self #
def hash #
def inspect(io) #
def name : String #

Returns the name of this class.

    String.name # => "String"

def nilable? #

Returns `true` if this class is `Nil`.

    Int32.nilable? # => false
    Nil.nilable?   # => true

def to_s(io) #
def |(other : U.class) forall U #

Returns the union type of `self` and other.

    Int32 | Char # => (Int32 | Char)

## Macro Detail

macro class_getter(*names) #

Defines getter methods for each of the given arguments.

Writing:

    class Person
      class_getter name
    end

Is the same as writing:

    class Person
      def self.name
        @@name
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_getter :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      class_getter name : String
    end

Is the same as writing:

    class Person
      @@name : String

      def self.name : String
        @@name
      end
    end

The type declaration can also include an initial value:

    class Person
      class_getter name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @@name : String = "John Doe"

      def self.name : String
        @@name
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      class_getter name = "John Doe"
    end

Is the same as writing:

    class Person
      @@name = "John Doe"

      def self.name : String
        @@name
      end
    end

If a block is given to the macro, a getter is generated with a variable that is lazily initialized with the block's contents:

    class Person
      class_getter(birth_date) { Time.now }
    end

Is the same as writing:

    class Person
      def self.birth_date
        @@birth_date ||= Time.now
      end
    end

macro class_getter!(*names) #

Defines raise-on-nil and nilable getter methods for each of the given arguments.

Writing:

    class Person
      class_getter! name
    end

Is the same as writing:

    class Person
      def self.name?
        @@name
      end

      def self.name
        @@name.not_nil!
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_getter! :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type, as nilable.

    class Person
      class_getter! name : String
    end

is the same as writing:

    class Person
      @@name : String?

      def self.name?
        @@name
      end

      def self.name
        @@name.not_nil!
      end
    end

macro class_getter?(*names) #

Defines query getter methods for each of the given arguments.

Writing:

    class Person
      class_getter? happy
    end

Is the same as writing:

    class Person
      def self.happy?
        @@happy
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_getter? :happy, "famous"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      class_getter? happy : Bool
    end

is the same as writing:

    class Person
      @@happy : Bool

      def self.happy? : Bool
        @@happy
      end
    end

The type declaration can also include an initial value:

    class Person
      class_getter? happy : Bool = true
    end

Is the same as writing:

    class Person
      @@happy : Bool = true

      def self.happy? : Bool
        @@happy
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      class_getter? happy = true
    end

Is the same as writing:

    class Person
      @@happy = true

      def self.happy?
        @@happy
      end
    end

macro class_property(*names) #

Defines property methods for each of the given arguments.

Writing:

    class Person
      class_property name
    end

Is the same as writing:

    class Person
      def self.name=(@@name)
      end

      def self.name
        @@name
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_property :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      class_property name : String
    end

Is the same as writing:

    class Person
      @@name : String

      def self.name=(@@name)
      end

      def self.name
        @@name
      end
    end

The type declaration can also include an initial value:

    class Person
      class_property name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @@name : String = "John Doe"

      def self.name=(@@name : String)
      end

      def self.name
        @@name
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      class_property name = "John Doe"
    end

Is the same as writing:

    class Person
      @@name = "John Doe"

      def self.name=(@@name : String)
      end

      def self.name
        @@name
      end
    end

If a block is given to the macro, a property is generated with a variable that is lazily initialized with the block's contents:

    class Person
      class_property(birth_date) { Time.now }
    end

Is the same as writing:

    class Person
      def self.birth_date
        @@birth_date ||= Time.now
      end

      def self.birth_date=(@@birth_date)
      end
    end

macro class_property!(*names) #

Defines raise-on-nil property methods for each of the given arguments.

Writing:

    class Person
      class_property! name
    end

Is the same as writing:

    class Person
      def self.name=(@@name)
      end

      def self.name?
        @@name
      end

      def self.name
        @@name.not_nil!
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_property! :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type, as nilable.

    class Person
      class_property! name : String
    end

Is the same as writing:

    class Person
      @@name : String?

      def self.name=(@@name)
      end

      def self.name?
        @@name
      end

      def self.name
        @@name.not_nil!
      end
    end

macro class_property?(*names) #

Defines query property methods for each of the given arguments.

Writing:

    class Person
      class_property? happy
    end

Is the same as writing:

    class Person
      def self.happy=(@@happy)
      end

      def self.happy?
        @@happy
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_property? :happy, "famous"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      class_property? happy : Bool
    end

Is the same as writing:

    class Person
      @@happy : Bool

      def self.happy=(@@happy)
      end

      def self.happy?
        @@happy
      end

      def self.happy
        @@happy.not_nil!
      end
    end

The type declaration can also include an initial value:

    class Person
      class_property? happy : Bool = true
    end

Is the same as writing:

    class Person
      @@happy : Bool = true

      def self.happy=(@@happy : Bool)
      end

      def self.happy? : Bool
        @@happy
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      class_property? happy = true
    end

Is the same as writing:

    class Person
      @@happy = true

      def self.happy=(@@happy)
      end

      def self.happy?
        @@happy
      end
    end

macro class_setter(*names) #

Defines setter methods for each of the given arguments.

Writing:

    class Person
      class_setter name
    end

Is the same as writing:

    class Person
      def self.name=(@@name)
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      class_setter :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      class_setter name : String
    end

is the same as writing:

    class Person
      @@name : String

      def self.name=(@@name : String)
      end
    end

The type declaration can also include an initial value:

    class Person
      class_setter name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @@name : String = "John Doe"

      def self.name=(@@name : String)
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      class_setter name = "John Doe"
    end

Is the same as writing:

    class Person
      @@name = "John Doe"

      def self.name=(@@name)
      end
    end

macro def_clone #

Defines a `#clone` method that returns a copy of this object with all instance variables cloned (`#clone` is in turn invoked on them).

macro def_equals(*fields) #

Defines an `#==` method by comparing the given fields.

The generated `#==` method has a self restriction.

    class Person
      def initialize(@name, @age)
      end

      # Define a `==` method that compares @name and @age
      def_equals @name, @age
    end

macro def_equals_and_hash(*fields) #

Defines `#hash` and `#==` method from the given fields.

The generated `#==` method has a self restriction.

    class Person
      def initialize(@name, @age)
      end

      # Define a hash method based on @name and @age
      # Define a `==` method that compares @name and @age
      def_equals_and_hash @name, @age
    end

macro def_hash(*fields) #

Defines a `#hash` method computed from the given fields.

    class Person
      def initialize(@name, @age)
      end

      # Define a hash method based on @name and @age
      def_hash @name, @age
    end

macro delegate(*methods, to object) #

Delegate methods to to.

Note that due to current language limitations this is only useful when no captured blocks are involved.

    class StringWrapper
      def initialize(@string : String)
      end

      delegate downcase, to: @string
      delegate gsub, to: @string
      delegate empty?, capitalize, to: @string
    end

    wrapper = StringWrapper.new "HELLO"
    wrapper.downcase       # => "hello"
    wrapper.gsub(/E/, "A") # => "HALLO"
    wrapper.empty?         # => false
    wrapper.capitalize     # => "Hello"

macro forward_missing_to(delegate) #

Forwards missing methods to delegate.

    class StringWrapper
      def initialize(@string : String)
      end

      forward_missing_to @string
    end

    wrapper = StringWrapper.new "HELLO"
    wrapper.downcase       # => "hello"
    wrapper.gsub(/E/, "A") # => "HALLO"

macro getter(*names) #

Defines getter methods for each of the given arguments.

Writing:

    class Person
      getter name
    end

Is the same as writing:

    class Person
      def name
        @name
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      getter :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      getter name : String
    end

Is the same as writing:

    class Person
      @name : String

      def name : String
        @name
      end
    end

The type declaration can also include an initial value:

    class Person
      getter name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @name : String = "John Doe"

      def name : String
        @name
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      getter name = "John Doe"
    end

Is the same as writing:

    class Person
      @name = "John Doe"

      def name : String
        @name
      end
    end

If a block is given to the macro, a getter is generated with a variable that is lazily initialized with the block's contents:

    class Person
      getter(birth_date) { Time.now }
    end

Is the same as writing:

    class Person
      def birth_date
        @birth_date ||= Time.now
      end
    end

macro getter!(*names) #

Defines raise-on-nil and nilable getter methods for each of the given arguments.

Writing:

    class Person
      getter! name
    end

Is the same as writing:

    class Person
      def name?
        @name
      end

      def name
        @name.not_nil!
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      getter! :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type, as nilable.

    class Person
      getter! name : String
    end

is the same as writing:

    class Person
      @name : String?

      def name?
        @name
      end

      def name
        @name.not_nil!
      end
    end

macro getter?(*names) #

Defines query getter methods for each of the given arguments.

Writing:

    class Person
      getter? happy
    end

Is the same as writing:

    class Person
      def happy?
        @happy
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      getter? :happy, "famous"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      getter? happy : Bool
    end

is the same as writing:

    class Person
      @happy : Bool

      def happy? : Bool
        @happy
      end
    end

The type declaration can also include an initial value:

    class Person
      getter? happy : Bool = true
    end

Is the same as writing:

    class Person
      @happy : Bool = true

      def happy? : Bool
        @happy
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      getter? happy = true
    end

Is the same as writing:

    class Person
      @happy = true

      def happy?
        @happy
      end
    end

macro property(*names) #

Defines property methods for each of the given arguments.

Writing:

    class Person
      property name
    end

Is the same as writing:

    class Person
      def name=(@name)
      end

      def name
        @name
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      property :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      property name : String
    end

Is the same as writing:

    class Person
      @name : String

      def name=(@name)
      end

      def name
        @name
      end
    end

The type declaration can also include an initial value:

    class Person
      property name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @name : String = "John Doe"

      def name=(@name : String)
      end

      def name
        @name
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      property name = "John Doe"
    end

Is the same as writing:

    class Person
      @name = "John Doe"

      def name=(@name : String)
      end

      def name
        @name
      end
    end

If a block is given to the macro, a property is generated with a variable that is lazily initialized with the block's contents:

    class Person
      property(birth_date) { Time.now }
    end

Is the same as writing:

    class Person
      def birth_date
        @birth_date ||= Time.now
      end

      def birth_date=(@birth_date)
      end
    end

macro property!(*names) #

Defines raise-on-nil property methods for each of the given arguments.

Writing:

    class Person
      property! name
    end

Is the same as writing:

    class Person
      def name=(@name)
      end

      def name?
        @name
      end

      def name
        @name.not_nil!
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      property! :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type, as nilable.

    class Person
      property! name : String
    end

Is the same as writing:

    class Person
      @name : String?

      def name=(@name)
      end

      def name?
        @name
      end

      def name
        @name.not_nil!
      end
    end

macro property?(*names) #

Defines query property methods for each of the given arguments.

Writing:

    class Person
      property? happy
    end

Is the same as writing:

    class Person
      def happy=(@happy)
      end

      def happy?
        @happy
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      property? :happy, "famous"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      property? happy : Bool
    end

Is the same as writing:

    class Person
      @happy : Bool

      def happy=(@happy)
      end

      def happy?
        @happy
      end

      def happy
        @happy.not_nil!
      end
    end

The type declaration can also include an initial value:

    class Person
      property? happy : Bool = true
    end

Is the same as writing:

    class Person
      @happy : Bool = true

      def happy=(@happy : Bool)
      end

      def happy? : Bool
        @happy
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      property? happy = true
    end

Is the same as writing:

    class Person
      @happy = true

      def happy=(@happy)
      end

      def happy?
        @happy
      end
    end

macro setter(*names) #

Defines setter methods for each of the given arguments.

Writing:

    class Person
      setter name
    end

Is the same as writing:

    class Person
      def name=(@name)
      end
    end

The arguments can be string literals, symbol literals or plain names:

    class Person
      setter :name, "age"
    end

If a type declaration is given, a variable with that name is declared with that type.

    class Person
      setter name : String
    end

is the same as writing:

    class Person
      @name : String

      def name=(@name : String)
      end
    end

The type declaration can also include an initial value:

    class Person
      setter name : String = "John Doe"
    end

Is the same as writing:

    class Person
      @name : String = "John Doe"

      def name=(@name : String)
      end
    end

An assignment can be passed too, but in this case the type of the variable must be easily inferrable from the initial value:

    class Person
      setter name = "John Doe"
    end

Is the same as writing:

    class Person
      @name = "John Doe"

      def name=(@name)
      end
    end