Class: KatakataIrb::Types::InstanceType

Inherits:
Object
  • Object
show all
Defined in:
lib/katakata_irb/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, params = {}) ⇒ InstanceType

Returns a new instance of InstanceType.



192
193
194
195
# File 'lib/katakata_irb/types.rb', line 192

def initialize(klass, params = {})
  @klass = klass
  @params = params
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



191
192
193
# File 'lib/katakata_irb/types.rb', line 191

def klass
  @klass
end

#paramsObject (readonly)

Returns the value of attribute params.



191
192
193
# File 'lib/katakata_irb/types.rb', line 191

def params
  @params
end

Instance Method Details

#all_methodsObject



198
# File 'lib/katakata_irb/types.rb', line 198

def all_methods() = rbs_methods.keys | @klass.instance_methods | @klass.private_instance_methods

#constantsObject



199
# File 'lib/katakata_irb/types.rb', line 199

def constants() = []

#inspectObject



210
211
212
213
214
215
216
217
# File 'lib/katakata_irb/types.rb', line 210

def inspect
  if params.empty?
    inspect_without_params
  else
    params_string = "[#{params.map { "#{_1}: #{_2.inspect}" }.join(', ')}]"
    "#{inspect_without_params}#{params_string}"
  end
end

#inspect_without_paramsObject



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/katakata_irb/types.rb', line 218

def inspect_without_params
  if klass == NilClass
    'nil'
  elsif klass == TrueClass
    'true'
  elsif klass == FalseClass
    'false'
  else
    klass.singleton_class? ? klass.superclass.to_s : klass.to_s
  end
end

#methodsObject



197
# File 'lib/katakata_irb/types.rb', line 197

def methods() = rbs_methods.select { _2.public? }.keys | @klass.instance_methods

#nillable?Boolean

Returns:

  • (Boolean)


201
# File 'lib/katakata_irb/types.rb', line 201

def nillable?() = (@klass == NilClass)

#nonnillableObject



202
# File 'lib/katakata_irb/types.rb', line 202

def nonnillable() = self

#rbs_methodsObject



203
204
205
206
207
208
209
# File 'lib/katakata_irb/types.rb', line 203

def rbs_methods
  name = KatakataIrb::Types.class_name_of(@klass)
  return {} unless name && KatakataIrb::Types.rbs_builder

  type_name = RBS::TypeName(name).absolute!
  KatakataIrb::Types.rbs_builder.build_instance(type_name).methods rescue {}
end

#transform {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



196
# File 'lib/katakata_irb/types.rb', line 196

def transform() = yield(self)

#typesObject



200
# File 'lib/katakata_irb/types.rb', line 200

def types() = [self]