README.md in rubype-0.2.0 vs README.md in rubype-0.2.1

- old
+ new

@@ -1,11 +1,58 @@ -# Ruby with Type. +# Ruby + Type = Rubype +```rb +def sum(x, y) + x + y +end +typesig sum: [Numeric, Numeric => Numeric] +``` + +This gem brings you advantage of type without changing existing code's behavior. + Matz has mentioned Ruby3.0 with static type at some confluences. But almost all rubyists(include me) are not sure how typed Ruby is. But it's worth thinking more. This gem is kind of trial without so much side-effect. +# Feature +### Typed method can coexist with non-typed method + +```ruby +# It's totally OK!! +class MyClass + def method_with_type(x, y) + x + y + end + typesig sum: [Numeric, Numeric => Numeric] + + def method_without_type(x, y) + 'string' + end +end +``` + +### Duck typing + +```ruby + +class MyClass + def foo(any_obj) + 1 + end + typesig sum: [Any => Numeric] +end + +# It's totally OK!! +MyClass.new.foo(1) +# It's totally OK!! +MyClass.new.foo('str') +``` + +### Advantage of type +* Meaningful error +* Executable documentation + ```rb require 'rubype' # ex1 class MyClass @@ -43,44 +90,12 @@ People.new.marry('non people') #=> ArgumentError: Wrong type of argument, type of "non people" should be People ``` -## Feature -### Typed method can coexist with non-typed method -```ruby -# It's totally OK!! -class MyClass - def sum(x, y) - x + y - end - typesig sum: [Numeric, Numeric => Numeric] - def sum_without_type(x, y) - 'string' - end -end -``` - -### Duck typing - -```ruby - -class MyClass - def foo(any_obj) - 1 - end - typesig sum: [Any => Numeric] -end - -# It's totally OK!! -MyClass.new.foo(1) -# It's totally OK!! -MyClass.new.foo('str') -``` - ## Installation gem install rubype or add gem 'rubype' to your Gemfile. This gem requires Ruby 2.0.0+. @@ -102,6 +117,7 @@ Push to the branch (`git push origin my-new-feature`) Create a new Pull Request ## Credits -[@chancancode](https://github.com/chancancode) first brought this to my attention. I've stolen some idea from him. +[@chancancode](https://github.com/chancancode) and [This article](http://blog.codeclimate.com/blog/2014/05/06/gradual-type-checking-for-ruby/) first brought this to my attention. I've stolen some idea from them. +