-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two questions: #to_hash and custom units #22
Comments
On the On the person unit, that seems a little weird since it's just a count of something. That's essentially what an However, you piqued my interest with the custom units idea. I poked around a bit in irb, and I was able to get a custom unit loaded: person_data = {:names=>"Person", :symbol=>"person", :primary_code=>"person", :scale=>{:value=>1.0, :unit_code=>"1"}, classification: "dimless"}
person = Unitwise::Atom.new(person_data)
Unitwise::Atom.all << person
Unitwise(10, "person")**2
=> #<Unitwise::Measurement value=100 unit=Pers2> A few caveats here:
|
The situation is here: https://github.com/molybdenum-99/reality ar = Reality.country('Argentina')
# => #<Reality::Country(Argentina)>
ar.population
# => #<Reality::Measure(43,417,000 person)>
ar.area
# => #<Reality::Measure(2,780,400 km²)>
ar.population + ar.area
# ArgumentError: 43,417,000person incompatible with 2,780,400km²
ar.population / ar.area
# => #<Reality::Measure(15 person/km²)> In other words, I need for that project "controlled units" and "pretty output" much more than "smart conversions". And I'm curious if Unitwise is a right tool for the task. |
(Sorry, it's currently not an bug report/feature request, rather a questions. I am currently evaluating Unitwise for my tasks and haven't find another way to communicate.)
About
#to_hash
methodsAs far as I know, Ruby has following convention:
to_h
if it can be somehow converted to hash;to_hash
if it thinks of itself as a some kind of hash.Unitwise's classes currently define
to_hash
method, while, I think, they can not be seen as "some kind of hash".Theoretical example of bad consequences:
Practical examle of bad consequences: when using awesome_print gem in irb (which is pretty common), it outputs those large hashes instead of compact
#inspect
results.About custom units
Unitwise provides very cool, effective, well-writen and well-tested code for working with units. What could make me (and, maybe, not only me?) happy is possibility, optional, to work with any units outside the controlled dictionary. Supposed synopsys:
WDYT?
The text was updated successfully, but these errors were encountered: