Project

General

Profile

Actions

Bug #7969

closed

Integer binary_op Float operations doesn't use coercion

Added by prijutme4ty (Ilya Vorontsov) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.3; 2.0.0
Backport:
[ruby-core:52937]

Description

I'm trying to override #coerce method on Float. But I found that redefining Float#coerce makes no changes in behavior of code: 1 + 2.0
class Float
def coerce(other)
[2, 2]
end
end
puts 1+2.0 # ==> 3.0 while result should be 4.

Is it done due to perfomance considerations or it's just a bug? If it's intended is it a spec or realization specific feature?

Updated by nobu (Nobuyoshi Nakada) about 11 years ago

  • Status changed from Open to Rejected

Intended behavior.
coerce method is called if the peer is unknown to the receiver.

Actions

Also available in: Atom PDF

Like0
Like0