Created
February 7, 2019 15:10
-
-
Save jnicklas/26c00c348a155965876291824f7db4dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client | |
attr_reader :key, | |
def initialize(key) | |
@key = key | |
end | |
end | |
Client.new("moo") # results in: ArgumentError: wrong number of arguments (given 1, expected 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you figure it out? Expand for spoiler!
There is a trailing comma on the
attr_reader
. This causes the parser to see this as:Since method definitions return their own name, this is effectively the same as:
So the initialize function gets overwritten with a reader for he
@initialize
instance variable.