I'm currently going through "The Well Grounded Rubyist 2nd Edition" I'm on page 296 and have been given the following code
class Person
attr_accessor :age
def initialize(options)
self.age = options[:age]
end
def teenager?
(13..19) === age
end
end
what does options[:age]
refer to?
is it an optional argument or something?
If I were writing that class, I would have written that line like @age = options
Edit - I forgot to mention, I did find this question - Rails optional argument - that uses the line used in the book. But i couldn't work out why it was used or why options
was used with the symbol [:age]
.