Extend the number class

后端 未结 3 822
离开以前
离开以前 2021-01-24 10:12

I want to extend the number class to have instance functions such as odd and even so I can do something like this:

2.odd() => false
         


        
3条回答
  •  天命终不由人
    2021-01-24 10:25

    I'd like to point out that that is already available in the numbers class.

    Just use the boolean methods, odd? and even?

    2.odd?
    => false
    
    2.even?
    => true
    

    Hope this helps.

    No need to create a new class, it already exists in the numbers class.

提交回复
热议问题