这是我的项目目录中的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