struct

Log::Metadata::Value

Inherits Struct / Value / Object

Constructors

new(raw : Type)

Creates a Log::Metadata::Value that wraps the given Type.

Source
new(hash : NamedTuple | Hash)

Creates Log::Metadata from the given values. All keys are converted to String

Source

Instance methods

==(other : self)

Returns true if both self and other's raw object are equal.

Source
==(other)

Returns true if the raw object is equal to other.

Source
[](index_or_key) : self

Assumes the underlying value is an Array or Hash and returns the element at the given index_or_key.

Raises if the underlying value is not an Array nor a Hash.

Source
[]?(index_or_key) : self | Nil

Assumes the underlying value is an Array or Hash and returns the element at the given index_or_key, or nil if out of bounds or the key is missing.

Raises if the underlying value is not an Array nor a Hash.

Source
as_a

Checks that the underlying value is Array(self), and returns its value. Raises otherwise.

as_a?

Checks that the underlying value is Array(self), and returns its value. Returns nil otherwise.

as_bool

Checks that the underlying value is Bool, and returns its value. Raises otherwise.

as_bool?

Checks that the underlying value is Bool, and returns its value. Returns nil otherwise.

as_f

Checks that the underlying value is Float32, and returns its value. Raises otherwise.

as_f64

Checks that the underlying value is Float64, and returns its value. Raises otherwise.

as_f64?

Checks that the underlying value is Float64, and returns its value. Returns nil otherwise.

as_f?

Checks that the underlying value is Float32, and returns its value. Returns nil otherwise.

as_h

Checks that the underlying value is Hash(String, self), and returns its value. Raises otherwise.

as_h?

Checks that the underlying value is Hash(String, self), and returns its value. Returns nil otherwise.

as_i

Checks that the underlying value is Int32, and returns its value. Raises otherwise.

as_i64

Checks that the underlying value is Int64, and returns its value. Raises otherwise.

as_i64?

Checks that the underlying value is Int64, and returns its value. Returns nil otherwise.

as_i?

Checks that the underlying value is Int32, and returns its value. Returns nil otherwise.

as_nil

Checks that the underlying value is Nil, and returns its value. Raises otherwise.

as_s

Checks that the underlying value is String, and returns its value. Raises otherwise.

as_s?

Checks that the underlying value is String, and returns its value. Returns nil otherwise.

as_time

Checks that the underlying value is Time, and returns its value. Raises otherwise.

as_time?

Checks that the underlying value is Time, and returns its value. Returns nil otherwise.

as_u

Checks that the underlying value is UInt32, and returns its value. Raises otherwise.

as_u64

Checks that the underlying value is UInt64, and returns its value. Raises otherwise.

as_u64?

Checks that the underlying value is UInt64, and returns its value. Returns nil otherwise.

as_u?

Checks that the underlying value is UInt32, and returns its value. Returns nil otherwise.

clone

Returns a new Log::Metadata::Value instance with the raw value cloneed.

Source
dig(index_or_key, *subkeys) : self

Traverses the depth of a structure and returns the value, otherwise raises.

Source
dig?(index_or_key, *subkeys) : self | Nil

Traverses the depth of a structure and returns the value. Returns nil if not found.

Source
dup

Returns a new Log::Metadata::Value instance with the raw value duped.

Source
hash(hasher)

See Object#hash(hasher)

inspect(io : IO) : Nil

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Source
raw

Returns the raw underlying value, a Type.

size

Assumes the underlying value is an Array or Hash and returns its size.

Raises if the underlying value is not an Array or Hash.

Source
to_json(builder : JSON::Builder) : Nil

Returns Log::Metadata::Value as JSON value.

NOTE: require "log/json" is required to opt-in to this feature.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source

Nested types