ruby-units icon indicating copy to clipboard operation
ruby-units copied to clipboard

Cannot create Unit object with hash

Open Nowaker opened this issue 9 years ago • 1 comments

    # 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'

Nowaker avatar Jun 12 '16 06:06 Nowaker

At least remove this usage from the documentation.

sshaw avatar Jul 07 '19 21:07 sshaw