If there is a defined built in ruby method, is it always preferable to use the built-in method?
If I have code such as:
if i == 0
What is the advantage to instead using the built-in ruby method?
if i.zero?
i.zero?
works only if i
is Numeric
object.
i = nil
i == 0
# => false
i.zero?
# NoMethodError: undefined method `zero?' for nil:NilClass
# from (irb):5
# from C:/Ruby200-x64/bin/irb:12:in `<main>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With