これは私のプロジェクトディレクトリにあるrspec
binstubです。コメント "frozen_string_literal:true"は何をしますか?
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rspec-core", "rspec")
これは何を意図していますか?
# frozen_string_literal: true
文字列のフリーズに関する重要なことは、[アプリケーションのパフォーマンスを向上させる]ことです(https://bugs.ruby-lang.org/issues/8976#note-30)。また、[here](https://blog.lucascaton.com.br/2016/01/19/what-is-frozen_string_literal-in-ruby/)も参照してください。 –
@ dave-schweisguth ' - " foo " '' foo ".freeze'と同じにする? '( - " foo ").__ id__'をチェックすると毎回違う値が得られますが、foo" .freeze .__ id__ "は毎回同じです。何か案は? – lilole
この関数が問題であるかどうかは、単項マイナスでのみ呼び出されるようです。 https://github.com/ruby/ruby/blob/trunk/string.c#L2572 – lilole