這是我的項目目錄中的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)。另見[這裏](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