struct Athena::HTTPKernel::Controller::ParameterMetadata(T)
inherits Struct
#
Represents a controller action parameter. Stores metadata associated with it, such as its name, type, and default value if any.
Methods#
#default_value : T#
Returns the default value for this parameter, raising an exception if it does not have one.
#default_value? : T | ::Nil#
Returns the default value for this parameter, or nil if it does not have one.
#first_type_of(klass : Type.class) forall Type#
Returns the metaclass of the first matching type variable that is an #instance_of? the provided klass, or nil if none match.
If this the #type is union, this would be the first viable type.
AHK::Controller::ParameterMetadata(Int32).new("foo").first_type_of(Int32) # => Int32.class
AHK::Controller::ParameterMetadata(String | Int32 | Bool).new("foo").first_type_of(Int32) # => Int32.class
AHK::Controller::ParameterMetadata(String | Int8 | Float64 | Int64).new("foo").first_type_of(Number) # => Float64.class
AHK::Controller::ParameterMetadata(String | Int32 | Bool).new("foo").first_type_of(Float64) # => nil
#has_default? : Bool#
Returns true if this parameter has a default value set, otherwise false.
#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)"
#instance_of?(klass : Type.class) : Bool forall Type#
Returns true if this parameter's #type includes the provided klass.
AHK::Controller::ParameterMetadata(Int32).new("foo").instance_of?(Int32) # => true
AHK::Controller::ParameterMetadata(Int32 | Bool).new("foo").instance_of?(Bool) # => true
AHK::Controller::ParameterMetadata(Int32).new("foo").instance_of?(String) # => false