Class: Steep::Interface::Shape

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/interface/shape.rb

Defined Under Namespace

Classes: Entry, MethodOverload, Methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, private:, methods: nil) ⇒ Shape

Returns a new instance of Shape.



201
202
203
204
205
# File 'lib/steep/interface/shape.rb', line 201

def initialize(type:, private:, methods: nil)
  @type = type
  @private = private
  @methods = methods || Methods.new(substs: [], methods: {})
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



199
200
201
# File 'lib/steep/interface/shape.rb', line 199

def methods
  @methods
end

#typeObject (readonly)

Returns the value of attribute type.



198
199
200
# File 'lib/steep/interface/shape.rb', line 198

def type
  @type
end

Instance Method Details

#private?Boolean

Returns:

  • (Boolean)


226
227
228
# File 'lib/steep/interface/shape.rb', line 226

def private?
  @private
end

#public?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/steep/interface/shape.rb', line 230

def public?
  !private?
end

#public_shapeObject



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/steep/interface/shape.rb', line 234

def public_shape
  if public?
    self
  else
    @public_shape ||= Shape.new(
      type: type,
      private: false,
      methods: methods.public_methods
    )
  end
end

#subst(s, type: nil) ⇒ Object



215
216
217
218
219
220
221
222
223
224
# File 'lib/steep/interface/shape.rb', line 215

def subst(s, type: nil)
  ty =
    if type
      type
    else
      self.type.subst(s)
    end

  Shape.new(type: ty, private: private?, methods: methods.push_substitution(s))
end

#to_sObject



207
208
209
# File 'lib/steep/interface/shape.rb', line 207

def to_s
  "#<#{self.class.name}: type=#{type}, private?=#{@private}, methods={#{methods.each_name.sort.join(", ")}}"
end

#update(type: self.type, methods: self.methods) ⇒ Object



211
212
213
# File 'lib/steep/interface/shape.rb', line 211

def update(type: self.type, methods: self.methods)
  _ = self.class.new(type: type, private: private?, methods: methods)
end