2024-05-28 eval_gemfile
eval_gemfile
が複数Gemfile用意したいときに便利。
- instance_eval(
- File.read('Gemfile')
- )
+ eval_gemfile('Gemfile')
ref. eval_gemfile
eval_gemfile in Ruby LSP
Ruby LSP が生成する Gemfile
でもeval_gemfile
が使われている。
.ruby-lsp/Gemfile
の内容。
# This custom gemfile is automatically generated by the Ruby LSP.
# It should be automatically git ignored, but in any case: do not commit it to your repository.
eval_gemfile(File.expand_path("../Gemfile", __dir__))
gem "ruby-lsp", require: false, group: :development
gem "debug", require: false, group: :development, platforms: :mri
gem "ruby-lsp-rails", require: false, group: :development
dependencies in Gemfile
Gemfile
内で依存性をイジりたい場合は、dependencies
を使うのが便利。
# Gemfile
dependencies
#=> [Gem::Dependency.new("rails", Gem::Requirement.new(["= 7.0.8.3"]), :runtime)]
# 依存性をイジる
# dependencies.delete_if