Skip to content

Instantly share code, notes, and snippets.

@hinrik

hinrik/type.cr Secret

Created December 25, 2018 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinrik/37921b9b2cb1668be6843e32ace1eb78 to your computer and use it in GitHub Desktop.
Save hinrik/37921b9b2cb1668be6843e32ace1eb78 to your computer and use it in GitHub Desktop.
class Foo
@foo : String | Int32 | Bool?
@bar : String | Int32 | Bool?
def initialize(@foo, @bar)
end
def bla
foo = @foo
bar = @bar
if foo.is_a? String && bar.is_a? String
puts foo + bar
elsif foo.is_a? Int32 && bar.is_a? Int32
puts foo + bar
end
# => undefined method '+' for Bool
#if foo.is_a? String && bar.is_a? String ||
# foo.is_a? Int32 && bar.is_a? Int32
# puts foo + bar
#end
end
end
foo = Foo.new(4, 5)
foo.bla()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment