halogenandtoast / alchemist

A scientific conversion library.
155 stars 28 forks source link

Weird operation behaviors #12

Closed willcosgrove closed 11 years ago

willcosgrove commented 11 years ago

I'm not sure I understand why anyone would want this kind of behavior:

height = 69.in
height #=> 69.0
height + 1 #=> 70.0
height #=> 70.0
height - 1 #=> 69.0
height #=> 69.0
height * 2 #=> 138.0
height #=> 138.0
height / 2 #=> 69.0
height #=> 69.0

Why are the +, -, *, and / operators acting like their +=, -=, *=, and /= counterparts?

I discovered this while I was trying to write a method that takes a height, like 69.in, and displays it as 5'9". Seemed like a straightforward problem:

def display_height(height)
  "#{height.to_i/12}'#{height.to_i%12}\""
end

Except that the height variable keeps changing on me. So it looks like the only way around it right now is to set height = height.value.to_i, which will give me good ol' Fixnum back instead of an Alchemist::NumericConversion.

halogenandtoast commented 11 years ago

This will be fixed soon.

halogenandtoast commented 11 years ago

Just pushed a fix to master. Sorry my definition of soon was a little lax. I'll probably be releasing a new gem tomorrow.