Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
Last active December 17, 2015 08:49
Show Gist options
  • Save AJFaraday/5582745 to your computer and use it in GitHub Desktop.
Save AJFaraday/5582745 to your computer and use it in GitHub Desktop.
brackets from cold
# any idea what's going on here?
>> ()
=> nil
>> (true)
=> true
>> ('string')
=> 'string'
>> (true,false)
SyntaxError: compile error
(irb):10: Can't assign to true
(true,false)
^
(irb):10: Can't assign to false
(irb):10: syntax error, unexpected '\n', expecting '='
from (irb):10
>> (a,b)
SyntaxError: compile error
(irb):11: syntax error, unexpected '\n', expecting '='
from (irb):11
>> (a,'a')
SyntaxError: compile error
(irb):12: syntax error, unexpected ')', expecting tCOLON2 or '[' or '.'
from (irb):12
@seanhandley
Copy link

Ignoring the paranthesis, it's expecting true, false\n to be a parallel variable assignment i.e.

a, b = c, d

but it's telling you off for trying to assign to true or false (they're immutable so unassignable) and then also telling you off for not putting in an equal sign to do parallel assignment with.

Similarly, if you do a, b\n then it expects an = for parallel assignment. The last one is right-evaluating the string 'a' and saying "You should put a colon here for hash assignment i.e. 'a': 'b' or you should be using the [] to access an element within this string e.g. 'a'[0] = 'a' or you should be using a dot and calling some string instance method on 'a' e.g. 'a'.upcase.

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