Sha256: 2c3719a1c6349380c2b0f7e6af95a92e5f25d9ec25bf128ee985bfa14da7e012

Contents?: true

Size: 1.25 KB

Versions: 73

Compression:

Stored size: 1.25 KB

Contents

# LengthCalculator shows three different method types having the same implementation.
#
# * It receives two objects.
# * It calls the `#size` method of the objects, and compare the return values.
# * It returns one of the objects which has bigger `#size` value.
#
class LengthCalculator
  interface _Sized
    def size: () -> Integer
  end

  # *Untyped* version -- all (static) type information is lost.
  #
  # You can pass any object, even if the object doesn't have `#size` method.
  #
  def max0: (untyped, untyped) -> untyped

  # *Subtyping* version -- with constraints on arguments, but the return type is inaccurate.
  #
  # You can type check if the object has `#size` method of the expected type.
  # However, the return type also has `_Sized` type, which drops other methods than `#size`.
  #
  def max1: (_Sized, _Sized) -> _Sized

  # *Generics* version -- the most advanced one in Steep/RBS
  #
  # You can type check if the object has `#size` method of the expected type.
  # And the return type is the one given as arguments.
  #
  # Note that the type system of Steep cannot ensure the given two objects have the same type.
  # Passing `String` and `Array[String]` will infer the return type `String | Array[String]`.
  #
  def max2: [T < _Sized] (T, T) -> T
end

Version data entries

73 entries across 73 versions & 3 rubygems

Version Path
steep-1.10.0 sample/sig/length.rbs
steep-1.10.0.pre.3 sample/sig/length.rbs
steep-1.10.0.pre.2 sample/sig/length.rbs
steep-1.10.0.pre.1 sample/sig/length.rbs
steep-1.10.0.dev.1 sample/sig/length.rbs
steep-relaxed-1.9.4.3 sample/sig/length.rbs
steep-relaxed-1.9.3.3 sample/sig/length.rbs
steep-activesupport-4-1.9.4 sample/sig/length.rbs
steep-activesupport-4-1.9.3.1 sample/sig/length.rbs
steep-1.9.4 sample/sig/length.rbs
steep-activesupport-4-1.9.3 sample/sig/length.rbs
steep-1.9.3 sample/sig/length.rbs
steep-1.9.2 sample/sig/length.rbs
steep-1.9.1 sample/sig/length.rbs
steep-1.9.0 sample/sig/length.rbs
steep-1.9.0.dev.2 sample/sig/length.rbs
steep-1.9.0.dev.1 sample/sig/length.rbs
steep-1.8.3 sample/sig/length.rbs
steep-1.8.2 sample/sig/length.rbs
steep-1.8.1 sample/sig/length.rbs