class Crystal::Macros::HashLiteral

Overview

A hash literal.

Defined in:

compiler/crystal/macros.cr

Instance Method Summary

Instance Method Detail

def [](key : ASTNode) : ASTNodeSource

Similar to Hash#[]?

def []=(key : ASTNode, value : ASTNode) : ASTNodeSource

Similar to Hash#[]=

def clear : HashLiteralSource

Similar to Hash#clear

def double_splat(trailing_string : StringLiteral = nil) : MacroIdSource

Returns a MacroId with all of this hash elements joined by commas.

If trailing_string is given, it will be appended to the result unless this hash is empty. This lets you splat a hash and optionally write a trailing comma if needed.

def each(&) : NilSource

Similar to Hash#each

def empty? : BoolLiteralSource

Similar to Hash#empty?

def keys : ArrayLiteralSource

Similar to Hash#keys

def map : ArrayLiteralSource

Similar to Hash#map

def of_key : ASTNode | NopSource

Returns the type specified at the end of the Hash literal, if any.

This refers to the key type after brackets in {} of String => Int32.

def of_value : ASTNode | NopSource

Returns the type specified at the end of the Hash literal, if any.

This refers to the value type after brackets in {} of String => Int32.

def size : NumberLiteralSource

Similar to Hash#size

def to_a : ArrayLiteral(TupleLiteral)Source

Similar to Hash#to_a

def type : Path | NopSource

Returns the type that receives the items of the array.

This refers to the part before brackets in MyHash{'a' => 1, 'b' => 2}

def values : ArrayLiteralSource

Similar to Hash#values

© 2012–2021 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.2.1/Crystal/Macros/HashLiteral.html