Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Created May 27, 2013 15:06
Show Gist options
  • Save lucassmagal/5657543 to your computer and use it in GitHub Desktop.
Save lucassmagal/5657543 to your computer and use it in GitHub Desktop.
def a
2
end
b = 3
a +b # ERROR!
a + b # 5
# 1.9.3-p194 :001 > def a
# 1.9.3-p194 :002?> 2
# 1.9.3-p194 :003?> end
# => nil
# 1.9.3-p194 :004 > b = 3
# => 3
# 1.9.3-p194 :005 > a +b
# ArgumentError: wrong number of arguments (1 for 0)
# from (irb):1:in `a'
# from (irb):5
# from /home/lmagalhaes/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
# 1.9.3-p194 :006 > a + b
# => 5
@pbalduino
Copy link

Isso acontece porque o whitespace funciona como um alias para o ponto, que é um alias para o método send

Ou seja:

    a + b => a.+(b) => a.send(:+, b)

a aqui é considerado um objeto porque retorna um FixNum

Quando você junta os dois, acontece isso:

    a +b => a(+b) => opa, a não recebe parâmetros, então tem coisa errada aqui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment