Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Yla's #Kaigieffect

Yla's #Kaigieffect

https://cookpad.connpass.com/event/282436/
手を動かして振り返る RubyKaigi 2023でLTしました.

Yla Aioi

May 18, 2023
Tweet

More Decks by Yla Aioi

Other Decks in Programming

Transcript

  1. class Generator < RbsRails::ActiveRecord::Generator private def pk_type pk = klass.primary_key

    return 'top' unless pk if pk.instance_of?(::CompositePrimaryKeys::CompositeKeys) sql_types = [] pk.each do |x| col = klass.columns.find { |column| column.name == x } sql_types << sql_type_to_class(col.type) end return sql_types.join(' | ') end col = klass.columns.find { |column| column.name == pk } sql_type_to_class(col.type) end end
  2. module SomeModule extend ActiveSupport::Concern included do # @type self: ClassMethods

    & singleton(ApplicationRecord) ... end 型注釈してあげる
  3. module Models::UndefinedDateTimeAttribute extend ActiveSupport::Concern module ClassMethods : Module def attr_undefined_datetime:

    (untyped column) -> void end end 実はこれどういう時に使うか 分かってない. moduleそのものの情報を足してあげる
  4. module ActiveRecord module AttributeMethods module Read extend ActiveSupport::Concern def read_attribute:

    (untyped attr_name) -> untyped | ... end end module Scoping module Named extend ActiveSupport::Concern module ClassMethods def scope: (untyped name, untyped body) -> untyped | ... end end end end
  5. ❯ bundle exec rbs -I sig method --singleton Hoge find

    ::hoge.find defined_in: ::_ActiveRecord_Relation_ClassMethods implementation: ::OfficialComicGroup accessibility: public types: (::Integer id) -> ::Hoge | (::Array[::Integer]) -> ::Array[::Hoge] | (*::Integer) -> ::Array[::Hoge] 便利だね〜〜〜