Class: RBI::SigParam

Inherits:
NodeWithComments show all
Defined in:
lib/rbi/model.rb

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#annotations, #comments?, #merge_with, #version_requirements

Methods inherited from Node

#compatible_with?, #detach, #merge_with, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string

Constructor Details

#initialize(name, type, loc: nil, comments: nil, &block) ⇒ SigParam

Returns a new instance of SigParam.

Signature:

  • (String name, (Type | String) type, ?loc: Loc?, ?comments: Array[Comment]?) ?{ (SigParam node) -> void } -> void



1179
1180
1181
1182
1183
1184
1185
# File 'lib/rbi/model.rb', line 1179

def initialize(name, type, loc: nil, comments: nil, &block)
  super(loc: loc, comments: comments)
  @name = name.to_s #: String
  @anonymous = name == "*" || name == "**" || name == "&" #: bool
  @type = type
  block&.call(self)
end

Instance Attribute Details

#nameObject (readonly)

Signature:

  • String



1173
1174
1175
# File 'lib/rbi/model.rb', line 1173

def name
  @name
end

#typeObject (readonly)

Signature:

  • (Type | String)



1176
1177
1178
# File 'lib/rbi/model.rb', line 1176

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object

Signature:

  • (Object other) -> bool



1199
1200
1201
1202
1203
# File 'lib/rbi/model.rb', line 1199

def ==(other)
  other.is_a?(SigParam) &&
    (name == other.name || anonymous? || other.anonymous?) &&
    type.to_s == other.type.to_s
end

#anonymous?Boolean

Signature:

  • -> bool

Returns:

  • (Boolean)


1194
1195
1196
# File 'lib/rbi/model.rb', line 1194

def anonymous?
  @anonymous
end

#to_sObject

Signature:

  • -> String



1189
1190
1191
# File 'lib/rbi/model.rb', line 1189

def to_s
  name
end