class RBS::Prototype::Runtime::ValueObjectBase

Public Class Methods

new(target_class) click to toggle source
# File rbs-3.4.4/lib/rbs/prototype/runtime/value_object_generator.rb, line 11
def initialize(target_class)
  @target_class = target_class
end

Public Instance Methods

build_decl() click to toggle source
# File rbs-3.4.4/lib/rbs/prototype/runtime/value_object_generator.rb, line 15
def build_decl
  decl = AST::Declarations::Class.new(
    name: to_type_name(only_name(@target_class)),
    type_params: [],
    super_class: build_super_class,
    members: [],
    annotations: [],
    location: nil,
    comment: nil
  )

  add_decl_members(decl)

  decl
end

Private Instance Methods

build_member_accessors(ast_members_class) click to toggle source

attr_accessor foo: untyped

# File rbs-3.4.4/lib/rbs/prototype/runtime/value_object_generator.rb, line 74
def build_member_accessors(ast_members_class)
  @target_class.members.map do |member|
    ast_members_class.new(
      name: member,
      ivar_name: nil,
      type: untyped,
      kind: :instance,
      location: nil,
      comment: nil,
      annotations: []
    )
  end
end
build_s_members() click to toggle source

def self.members: () -> [ :foo, :bar ] def members: () -> [ :foo, :bar ]

# File rbs-3.4.4/lib/rbs/prototype/runtime/value_object_generator.rb, line 35
def build_s_members
  (
    [:singleton, :instance] #: Array[AST::Members::MethodDefinition::kind]
  ).map do |kind|
    AST::Members::MethodDefinition.new(
      name: :members,
      overloads: [
        AST::Members::MethodDefinition::Overload.new(
          annotations: [],
          method_type: MethodType.new(
            type: Types::Function.empty(
              Types::Tuple.new(
                types: @target_class.members.map do |member|
                  if member.to_s.ascii_only?
                    Types::Literal.new(literal: member, location: nil)
                  else
                    BuiltinNames::Symbol.instance_type
                  end
                end,
                location: nil
              )
            ),
            type_params: [],
            block: nil,
            location: nil,
          )
        )
      ],
      kind: kind,
      location: nil,
      comment: nil,
      annotations: [],
      overloading: false,
      visibility: nil
    )
  end
end