Apart from making a nice symmetry with unary minus, why is unary plus operator defined on Numeric
class? Is there some practical value in it, except for causing confusion allowing writing things like ++i
(which, unlike most non-Rubyists would think, doesn't increment i
).
I can think of scenario where defining unary plus on a custom class could be useful (say if you're creating some sexy DSL), so being able to define it is ok, but why is it already defined on Ruby numbers?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…