Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Created July 28, 2018 14:50
Show Gist options
  • Save kevinhughes27/1e842fb16dac0e4e772f397500064905 to your computer and use it in GitHub Desktop.
Save kevinhughes27/1e842fb16dac0e4e772f397500064905 to your computer and use it in GitHub Desktop.
A trailing comma in a list of attr_reader hijacks the next method definition. How is this not a syntax error?
class Wat
def initialize(thing)
@thing = thing
@foo = 'foo'
end
# this ends up creating an attr_reader for foo
# but shouldn't it throw an error when it
# sees `def` after a comma?
attr_reader :thing,
def foo
'bar'
end
end
wat = Wat.new('thing')
puts wat.thing
#-> thing
puts wat.foo
# -> foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment