Skip to content
A collection about all things types, type signatures / annotations and more for ruby - incl. bool, bytes, buffer, enum, flag, record, data and more
Branch: master
Clone or download
Latest commit 1e7d82f Apr 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
i Delete dummy.txt Apr 22, 2019
README.md Update README.md Apr 22, 2019

README.md

Awesome Types & Type Signatures / Annotations for Ruby

Type Signatures / Annotations

Upcoming

Types

Bool

  • Bool Type :octocat: - safebool gem / library - safe bool / boolean type adds Bool(), to_b, parse_bool / to_bool, bool?, false?, true?, true.is_a?(Bool)==true, false.is_a?(Bool)==true, and more

Enums / Flags

  • Enum / Flag Types :octocat: - enums library / gem - safe enum / enumeration types - a set of symbolic keys bound to unique integer numbers (incl. bit flags option)

Bytes / Buffer / (Frozen) String

Records

  • Record Type :octocat: - records gem / library - frozen / immutable structs with copy on updates

Structs

Typed Arrays / Typed Hashes

  • Typed Arrays / Typed Hashes :octocat: - safestruct gem / library - safe data structures (array, hash, struct) - say goodbye to null / nil (and maybe) - say hello to zero

(Algebraic) Data (Union) Types with Variants

  • Data Type :octocat: - safedata gem / library - safe (algebraic) union data types with (enumerated) variants

More / Misc Types

  • Types :octocat: - dry-types gem / library - flexible type system with coercions and constraints

Ruby 3

Ruby 3 Expected for December 2020 (Hopefully) - Planned Next Version After Ruby 2.7 Expected for December 2019

Static Analysis

Ruby 3 static analysis will have four items:

  1. Type signature format (.rbi)
  2. Level-1 type checking tool
  3. Type signature profiling / prototyping tool
  4. Level-2 type checking tools

(Source: RubyKaigi 2019 Progress Report on Ruby 3 Talk Slides)

Crystal

Ruby with 100 % static types compiled to binaries via LLVM

Crystal is statically type checked, so any type errors will be caught early by the compiler rather than fail on runtime. Moreover, and to keep the language clean, Crystal has built-in type inference, so most type annotations are unneeded.

def shout(x)
  # Notice that both Int32 and String respond_to `to_s`
  x.to_s.upcase
end

foo = ENV["FOO"]? || 10

typeof(foo)        #=> (Int32 | String)
typeof(shout(foo)) #=> String

(Source: Crystal Lang - Type System)

All types are non-nilable in Crystal, and nilable variables are represented as a union between the type and nil. As a consequence, the compiler will automatically check for null references in compile time, helping prevent the dreadful billion-dollar mistake.

if rand(2) > 0
  my_string = "hello world"
end

puts my_string.upcase

Running the previous file:

$ crystal hello_world.cr
Error in hello_world.cr:5: undefined method 'upcase' for Nil (compile-time type is (String | Nil))

puts my_string.upcase
               ^~~~~~

(Source: Crystal Lang - Null Reference Checks)

Python

Learning from Type Checkers / Signatures / Annotations in Python

New in Python version 3.5.

The typing module supports type hints as specified by PEP 484 and PEP 526. The most fundamental support consists of the types Any, Union, Tuple, Callable, TypeVar, and Generic. For full specification please see PEP 484. For a simplified introduction to type hints see PEP 483.

More type checkers / signatures / annotations:

Meta

License

The awesome list is dedicated to the public domain. Use it as you please with no restrictions whatsoever.

Questions? Comments?

Send them along to the ruby-talk mailing list. Thanks!

You can’t perform that action at this time.