if inner_type.is_a?(::GraphQL::Schema::List) is_inner_type_non_null?(inner_type) end when ::GraphQL::Schema::List is_inner_type_non_null?(obj_type) else false end end def is_inner_type_non_null?(obj_type) inner_type = obj_type.of_type inner_type.is_a?(::GraphQL::Schema::NonNull) end パターンマッチ不使⽤ 8
if inner_type.is_a?(::GraphQL::Schema::List) is_inner_type_non_null?(inner_type) end when ::GraphQL::Schema::List is_inner_type_non_null?(obj_type) else false end end def element_non_null?(obj_type) case obj_type in { of_type: { of_type: ::GraphQL::Schema::NonNull} } | { of_type: ::GraphQL::Schema::NonNull} true else false end end def is_inner_type_non_null?(obj_type) inner_type = obj_type.of_type inner_type.is_a?(::GraphQL::Schema::NonNull) end パターンマッチ不使⽤ パターンマッチ使⽤!! 9
if inner_type.is_a?(::GraphQL::Schema::List) is_inner_type_non_null?(inner_type) end when ::GraphQL::Schema::List is_inner_type_non_null?(obj_type) else false end end スッキリ!!! def element_non_null?(obj_type) case obj_type in { of_type: { of_type: ::GraphQL::Schema::NonNull} } | { of_type: ::GraphQL::Schema::NonNull} true else false end end def is_inner_type_non_null?(obj_type) inner_type = obj_type.of_type inner_type.is_a?(::GraphQL::Schema::NonNull) end パターンマッチ不使⽤ パターンマッチ使⽤!! 10
Integer | in 1..9 === で比較。クラス・範囲・正規表現もここ Variableパターン in x / in ^x 値を束縛する。^ を付けると既存の変数の値と比較 Hashパターン in { name: String => n } #deconstruct_keys を呼ぶ。ハッシュにマッチするか Arrayパターン in [Integer, *rest] #deconstruct を呼ぶ。配列の要素にマッチするか Findパターン in [*, nil, *] 配列の中から条件に合う要素を探す Alternativeパターン in :a | :b | :c いずれかにマッチするか 12