README.md in konstructor-0.4.7 vs README.md in konstructor-1.0.0

- old
+ new

@@ -1,12 +1,16 @@ [![Gem Version](http://img.shields.io/gem/v/konstructor.svg)][gem] [![Build Status](https://travis-ci.org/snovity/konstructor.svg?branch=master)][travis] [![Coverage Status](https://coveralls.io/repos/github/snovity/konstructor/badge.svg?branch=master)][coveralls] +[![Code Climate](https://codeclimate.com/github/snovity/konstructor/badges/gpa.svg)][codeclimate] +[![Dependency Status](https://gemnasium.com/badges/github.com/snovity/konstructor.svg)][gemnasium] [gem]: https://rubygems.org/gems/konstructor [travis]: http://travis-ci.org/snovity/konstructor [coveralls]: https://coveralls.io/github/snovity/konstructor +[gemnasium]: https://gemnasium.com/snovity/konstructor +[codeclimate]: https://codeclimate.com/github/snovity/konstructor # Konstructor This is a small gem that gives you multiple constructors in Ruby. @@ -114,11 +118,11 @@ obj1 = SomeClass.create obj2 = SomeClass.recreate ``` If you decide to remove the default Ruby constructor for some reason, -you can effectively do it by marking it as private using Ruby +you can achieve the effect by marking it private with Ruby method `private_class_method`: ```ruby class SomeClass private_class_method :new @@ -185,31 +189,35 @@ Contract Num => SomeClass def create(some_number) @number = some_number end end + +obj0 = SomeClass.create(3) +obj1 = SomeClass.create("three") # raises contract exception ``` If you stumble upon a metaprogramming gem that conflicts with Konstructor, please [open an issue](https://github.com/snovity/konstructor/issues/new). ## Details -Ruby constructor is a pair consisting of public factory method defined -on a class and a private instance method. Therefore, to achieve -its goal `konstructor` marks instance method as private and defines a +The default Ruby constructor is a pair consisting of public +class method `new` and a private instance +method `initialize`. To create an additional one `konstructor` +marks given instance method as private and defines a corresponding public class method with the same name. #### Performance -Konstructor does all its work when class is being defined. Once class -has been defined, it's just standard Ruby instance creation. -Therefore, there is no runtime performance penalty. +Using `konstructor` declaration has no runtime perfomance penalty, +since all work is done during class definition and then it's just +standard Ruby instance creation. -As for the cost of declaring a constructor at initial load time, -it's roughly the same as declaring 3 properties with `attr_accessor`. +Cost of `konstructor` declaration at initial load time is roughly the +same as declaring 3 properties with `attr_accessor`. ```ruby attr_accessor :one, :two, :three # following declaration takes the same time as above declaration konstructor @@ -217,12 +225,13 @@ end ``` See [Benchmarks page](https://github.com/snovity/konstructor/wiki/Benchmarks) for details. -#### Dependencies +#### Dependencies and requirements -Konstructor doesn't depend on other gems. +Konstructor doesn't depend on other gems. +Requires Ruby `2.0.0` or higher. #### Thread safety Konstructor is thread safe.