0

I'm trying to implement a fucntion:

def foo(t : Class)
    if t in Int::Signed
        # ...
    end
end

But how to implement t in Int::Signed? Where Int::Signed

I know is_a?(Int::Signed) but here the parameter is of type Type. Thanks.

XQY
  • 552
  • 4
  • 17
  • I also know `case when`, but I think it's too long and ugly. – XQY Jun 29 '18 at 06:42
  • @Amadan sorry, it's `Class`. I have corrected my question. But `typeof(1_64) == Int::Signed` returns `false`. – XQY Jun 29 '18 at 06:49

1 Answers1

4
def foo(t : Class)
  if t < Int::Signed
    # ...
  end
end

Class#< is only added in Crystal 0.25, if I am not mistaken, so make sure you update if it does not work for you. There is also Class#<= that would return true for Int::Signed <= Int::Signed.

Amadan
  • 191,408
  • 23
  • 240
  • 301