Skip to content

Instantly share code, notes, and snippets.

@marciojrtorres
Created August 5, 2013 22:50
Show Gist options
  • Save marciojrtorres/6160345 to your computer and use it in GitHub Desktop.
Save marciojrtorres/6160345 to your computer and use it in GitHub Desktop.
Em Ruby, o comportamento da tipagem dinâmica e segura
def soma(a, b)
return a + b
end
soma("q", "w") # ok, imprime qw, o método "q".+("w") faz a concatenação
soma(2, 3) # ok, imprime 5, o método 2.+(3) faz a soma
soma("q", 3) # falha, não é possível somar string/número sem conversão
# explícita:
TypeError: can't convert Fixnum into String
from (irb):2:in `+'
from (irb):2:in `soma'
from (irb):6
from :0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment