olbrich / ruby-units

A unit handling library for ruby
MIT License
527 stars 109 forks source link

Cannot create Unit object with hash #138

Open Nowaker opened 8 years ago

Nowaker commented 8 years ago
    # Create a new Unit object.  Can be initialized using a String, a Hash, an Array, Time, DateTime
    #
    # @example Valid options include:
    # ...
    #  [1, 'kg']
    #  {:scalar => 1, :numerator=>'kg'}
    def initialize(*options)

The latter doesn't work as promised:

2.2.2 :012 > Unit.new({:scalar => 1, :numerator=>'kg'})
TypeError: no implicit conversion of Array into String
        from /home/nowaker/.rvm/gems/ruby-2.2.2/gems/ruby-units-2.0.0/lib/ruby_units/unit.rb:410:in `+'
        from /home/nowaker/.rvm/gems/ruby-2.2.2/gems/ruby-units-2.0.0/lib/ruby_units/unit.rb:410:in `is_base?'
        from /home/nowaker/.rvm/gems/ruby-2.2.2/gems/ruby-units-2.0.0/lib/ruby_units/unit.rb:1246:in `update_base_scalar'
        from /home/nowaker/.rvm/gems/ruby-2.2.2/gems/ruby-units-2.0.0/lib/ruby_units/unit.rb:344:in `initialize'
sshaw commented 5 years ago

At least remove this usage from the documentation.