Ruby Types

Ruby Types introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.

For example define:

class Boolean < Type
    def type_classes
        [TrueClass, FalseClass]
    end
end

Then you can call:

foo = 5
bar = true

foo.type_of? Boolean    # returns false
bar.type_of? Boolean    # returns true

Binding back to classic behaviour works:

foo.type_of? Numeric    # returns true

By overriding #type_types method of the Type class you can achieve also types inheritance by the same way as mentioned above.

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b 20101220-my-change).
  3. Commit your changes (git commit -am "Added something").
  4. Push to the branch (git push origin 20101220-my-change).
  5. Create an Issue with a link to your branch.
  6. Enjoy a refreshing Diet Coke and wait.

Copyright © 2011 Martin Kozák. See LICENSE.txt for further details.