我正在从0.5迁移到1.0.
在阅读时,我注意到两种不同的方式来声明属性,使用hostAttributes
和properties
.
这两个有什么区别?
我在config/application.rb中遵循了注释指南
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Run Code Online (Sandbox Code Playgroud)
但是当我加入Rails.application.config.eager_load_paths << Rails.root.join('lib')
时config/initializers/eager_load.rb
.
它抛出 <top (required)>': can't modify frozen Array (RuntimeError)
是的,如果我把它放在里面它是有效的config/application.rb
.
我想知道为什么它不能用于初始化器以及如何使用约定使其工作?
示例代码:
hash_of_array = { a: [] }
b = hash_of_array
c = hash_of_array
b[:a] << 1
puts b # => { a: [1] }
puts c # => { a: [1] }
Run Code Online (Sandbox Code Playgroud)
为什么两个变量的数组都有1?我只将它附加在变量上b
.
试穿
例如,在 https://github.com/locomotivecms/wagon/blob/master/Rakefile#L23上
desc 'build the gem and release it to rubygems.org'
task release: :gem do
sh "gem push pkg/locomotivecms_wagon-#{gemspec.version}.gem"
end
Run Code Online (Sandbox Code Playgroud)
当我跑rake --task
,它返回作为描述.
rake clobber_package # Remove package products
rake gem # Build the gem file locomotivecms_wagon-2.2.0.beta1.gem
rake package # Build all the packages
rake release # build the gem and release it to rubygems.org
rake repackage # Force a rebuild of the package files
rake spec # Run RSpec code examples
rake spec:integration # Run RSpec code examples …
Run Code Online (Sandbox Code Playgroud)