class Discord::Context

Overview

A Context instance is a container that can be used to store any kind of class to be later recalled:

class Foo
  getter value

  def initialize(@value : Int32)
  end
end

class Bar
  getter value

  def initialize(@value : String)
  end
end

context = Context.new
context.put Foo.new(1337)
context.put Bar.new("discord")

context[Foo].value # => 1337
context[Bar].value # => "discord"

Defined in:

discordcr-middleware/context.cr

Instance Method Summary

Instance Method Detail

def [](clazz : T.class) : T forall T #

Access a stored value by class


[View source]
def put(extension : T) forall T #

Store an object in this class. The object must be a class.


[View source]