Search code examples
crystal-lang

How to get the type of anything in Crystal?


In Javascript the use of typeof() allows you to quickly see what type of anything is, what is the equivalent in the Crystal?

Say the code below I wanted to check what type Crystal thought the object was.

  get "/" do
    object = {hello: "hello", world: "world"}
    object.to_json
    puts typeof(object)
  end

Solution

  • Sometimes google works wonders, I searched the API docs for typeof and found nothing. enter image description here

    It is just typeof() https://crystal-lang.org/reference/1.4/syntax_and_semantics/typeof.html