brew/Library/Homebrew/attrable.rb

31 lines
868 B
Ruby
Raw Normal View History

# typed: strict
# frozen_string_literal: true
# This module provides methods to define specialized attributes.
# Method stubs are generated by the {Tapioca::Compilers::Attrables} compiler.
# @note The compiler is fragile, and must be updated if the filename changes, if methods are added or removed,
# or if a method's arity changes.
module Attrable
2024-10-06 09:25:57 -07:00
extend T::Helpers
requires_ancestor { Module }
sig { params(attrs: Symbol).void }
def attr_predicate(*attrs)
attrs.each do |attr|
define_method attr do
instance_variable_get("@#{attr.to_s.sub(/\?$/, "")}") == true
end
end
end
sig { params(attrs: Symbol).void }
def attr_rw(*attrs)
attrs.each do |attr|
2023-12-31 11:29:57 -08:00
define_method attr do |val = nil|
val.nil? ? instance_variable_get(:"@#{attr}") : instance_variable_set(:"@#{attr}", val)
end
end
end
end