ruby/typeprof#460 の日本語版。
Ruby にはメソッドを動的に定義したり、モジュールを mix-in したりする DSL が数多くあります。
define_method(:hello) { "hi" }はレシーバにhelloを追加するForwardable#def_delegator :@target, :fooは委譲メソッドfooを生成する
ruby/typeprof#460 の日本語版。
Ruby にはメソッドを動的に定義したり、モジュールを mix-in したりする DSL が数多くあります。
define_method(:hello) { "hi" } はレシーバに hello を追加するForwardable#def_delegator :@target, :foo は委譲メソッド foo を生成する| # Rails(Zeitwerk)は `class Foo::Bar::Buz` の定義を見つけて、定数の探索パスに | |
| # `foo.rb` が存在しない場合にモジュール `Foo` を自動的に生成します。 | |
| # しかし、rbs-inline でRBSを生成すると `class Foo::Bar::Buz` をそのまま `*.rbs` に | |
| # 書き込むため、モジュール `Foo` が見つからずにエラーが起きます。 | |
| # | |
| # このタスクは上記のエラーが起きないように、Rails(Zeitwerk)が動的に生成する | |
| # モジュールを探し出し、全ての定義を `sig/generated/zeitwerk.rbs` に出力します。 | |
| task zeitwerk: :environment do | |
| namespace_keys = [] |
| namespace :rbs do | |
| task zeitwerk: :environment do | |
| namespace_keys = [] | |
| # 他のRakeタスクと続けて実行すると既にクラスを読み込んでいるため、 `__namespace_dirs` が | |
| # 空になってしまうので、リロードしておく。 | |
| Rails.autoloaders.main.reload | |
| # constantize すると `__namespace_dirs` が更新されるので、空になるまで繰り返す。 | |
| until Rails.autoloaders.main.__namespace_dirs.empty? |
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| # Phase to load libraries | |
| require_relative "../config/application" | |
| require 'orthoses/rails' | |
| require 'orthoses/yard' | |
| # You can choose logger level | |
| Orthoses.logger.level = :warn |
| version: 2.1 | |
| # this allows you to use CircleCI's dynamic configuration feature | |
| setup: true | |
| parameters: | |
| tree_sha_path: | |
| type: string | |
| default: ".git_tree_sha" | |
| tree_status_path: |
| # frozen_string_literal: true | |
| require 'sidekiq/logger' | |
| module App | |
| module Formatters | |
| class Sidekiq < ::Sidekiq::Logger::Formatters::Pretty | |
| def call(severity, time, _program_name, message) | |
| hash = { | |
| timestamp: time.utc.iso8601(3), |
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| # Rails v7.0.5以降におけるcreate_associationメソッドの影響範囲を調べるスクリプト | |
| # | |
| # ## 参考ページ | |
| # * Rails 7.0.5以降におけるcreate_associationメソッドの挙動変更についてまとめ | |
| # https://blog.willnet.in/entry/2023/07/04/113321 | |
| # * parser gemでRubyプログラムのバグを探す | |
| # https://nacl-ltd.github.io/2021/07/02/ruby-ast.html |
| # frozen_string_literal: true | |
| # This is a test script for create_association incompatibility. | |
| # | |
| # usage | |
| # * `RAILS_VERSION=7.0.4 ruby active_record_test.rb` | |
| # * `RAILS_VERSION=7.0.5 ruby active_record_test.rb` | |
| # | |
| # see also | |
| # * https://github.com/rails/rails/issues/48330 |
| class A | |
| @@foo = "foo" | |
| class << self | |
| @@bar = "bar" | |
| end | |
| end | |
| p A.class_variable_get(:@@foo) #=> "foo" | |
| p A.class_variable_get(:@@bar) #=> "bar" |
| module A; end | |
| module B; end | |
| module C; end | |
| class Foo | |
| include A | |
| include B | |
| include C | |
| end |