Reputation: 22064
My question related to the following 3 code excerpt:
code of class method: start(options = nil)
# File 'lib/rack/server.rb', line 136
def self.start(options = nil)
new(options).start
end
code of instance method: #initialize(options = nil)
# File 'lib/rack/server.rb', line 174
def initialize(options = nil)
@options = options
@app = options[:app] if options && options[:app]
end
code of instance method: #start
# File 'lib/rack/server.rb', line 229
def start
if options[:warn]
$-w = true
end
...# more lines that are not related to my question
end
my question is that Should the the local variable options
in the instance method start
be @options
?. In my option,as the first 2 excerpts shows that the options as parameter that pass to initialize
, and make it to a instance variable @options
, so in the instance method start, it should reference it as @options
, instead of options
, because the scope of options
can't be accessed by #start
Upvotes: 1
Views: 75
Reputation: 13719
In the same class there are getter method for options:
# File 'lib/rack/server.rb', line 180
def options
@options ||= parse_options(ARGV)
end
options
in #start
is a call to this method, not a local variable.
Upvotes: 5