1
次の3つのコードの抜粋に関連
クラスメソッドのコード:インスタンスメソッドのstart(options = nil)
# File 'lib/rack/server.rb', line 136
def self.start(options = nil)
new(options).start
end
コード:#initialize(options = nil)
# File 'lib/rack/server.rb', line 174
def initialize(options = nil)
@options = options
@app = options[:app] if options && options[:app]
end
インスタンスコードのコード:#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
私の質問は、インスタンスメソッドのローカル変数options
は@options
であるべきですか?私の選択肢では、最初の2つの抜粋は、initialize
に渡すパラメータとしてのオプションを示し、それをインスタンス変数@options
にするので、インスタンスメソッドの開始では、options
の代わりに@options
として参照する必要があります。 options
のオプションのためのゲッターメソッドがあり、同じクラスで#start
私の質問に答えてくれてありがとう、私はそれを理解することがとても満足です! – mko