Class: KatakataIrb::Types::InstanceType
- Inherits:
-
Object
- Object
- KatakataIrb::Types::InstanceType
- Defined in:
- lib/katakata_irb/types.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #all_methods ⇒ Object
- #constants ⇒ Object
-
#initialize(klass, params = {}) ⇒ InstanceType
constructor
A new instance of InstanceType.
- #inspect ⇒ Object
- #inspect_without_params ⇒ Object
- #methods ⇒ Object
- #nillable? ⇒ Boolean
- #nonnillable ⇒ Object
- #rbs_methods ⇒ Object
- #transform {|_self| ... } ⇒ Object
- #types ⇒ Object
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
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
191 192 193 |
# File 'lib/katakata_irb/types.rb', line 191 def klass @klass end |
#params ⇒ Object (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_methods ⇒ Object
198 |
# File 'lib/katakata_irb/types.rb', line 198 def all_methods() = rbs_methods.keys | @klass.instance_methods | @klass.private_instance_methods |
#constants ⇒ Object
199 |
# File 'lib/katakata_irb/types.rb', line 199 def constants() = [] |
#inspect ⇒ Object
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_params ⇒ Object
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 |
#methods ⇒ Object
197 |
# File 'lib/katakata_irb/types.rb', line 197 def methods() = rbs_methods.select { _2.public? }.keys | @klass.instance_methods |
#nillable? ⇒ Boolean
201 |
# File 'lib/katakata_irb/types.rb', line 201 def nillable?() = (@klass == NilClass) |
#nonnillable ⇒ Object
202 |
# File 'lib/katakata_irb/types.rb', line 202 def nonnillable() = self |
#rbs_methods ⇒ Object
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
196 |
# File 'lib/katakata_irb/types.rb', line 196 def transform() = yield(self) |
#types ⇒ Object
200 |
# File 'lib/katakata_irb/types.rb', line 200 def types() = [self] |