Avdi Grimm’s book “Confident Ruby” and my work on CallBaecker and defp I had an Idea for an implementation of soft typing in Ruby. My goal was to build a shorthand for ruby’s conversion methods syntactic similar to other languages. By relying on ruby’s conversion methods I preserved the initial flexibility of ruby. Furthermore I’ve added extended Error messages to ease debuging code. And you can add custom types.
So I’m happy to publish my take on soft typing in ruby.
class ExampleClass extend Rubysierung include CallBaecker def buz(foo: String, bar: Strict::String) [foo, bar] end end
class ExampleClass extend Rubysierung include CallBaecker def buz(foo: , bar: ) foo = foo.to_s bar = bar.to_str [foo, bar] end end
[ # Type , explicid, implicid [String, :to_s, :to_str], [Integer, :to_i, :to_int], [Array, :to_a, :to_ary], [Complex, :to_c, :to_c], [Float, :to_f, :to_f], [Hash, :to_h, :to_hash], [Rational, :to_r, :to_r], [IO, :to_io, :to_io], [Proc, :to_proc, :to_proc], [Symbol, :to_sym, :to_sym], [Thread, :join, :join] ]
In the future I want to add the possibility to use default values with a specified type. If you have any additional types, ideas or enhancements, feel free to open a pull request, issue or leave a comment :)
Head over to the repository.
25-11-2014: adit -> change ‘static typing’ to ‘soft typing’