Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6337 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 2 years ago

[PATCH] new Number methods (isOdd, isEven, addLeadingZero)

Reported by: Tobie Assigned to: sam
Priority: normal Milestone: 1.x
Component: Prototype Version:
Severity: normal Keywords:
Cc:

Description

Pretty basic stuff, nevertheless quite usefull:

* isEven and isOdd just return a Boolean:

(2).isOdd() // -> false
(2).isEven() // -> true

* addLeadingZero takes one param which is the expected total number of digits output, it always returns a string (rather than a Number):

(7).addLeadingZero()    // -> '07'
(7).addLeadingZero(0)   // -> '7'
(7).addLeadingZero(1)   // -> '7'
(7).addLeadingZero(2)   // -> '07'
(7).addLeadingZero(3)   // -> '007' now you get why I used 7 ;-)
(100).addLeadingZero(3) // -> '100'

unit tests provided.

Attachments

base.diff (0.6 kB) - added by Tobie on 10/03/06 03:50:45.
the js
base.2.diff (0.6 kB) - added by Tobie on 10/03/06 03:51:01.
the js
base.html.diff (1.3 kB) - added by Tobie on 10/03/06 03:54:44.
the correct tests

Change History

10/03/06 03:50:45 changed by Tobie

  • attachment base.diff added.

the js

10/03/06 03:51:01 changed by Tobie

  • attachment base.2.diff added.

the js

(in reply to: ↑ description ) 10/03/06 03:52:46 changed by Tobie

I'm not really sure why all of this is in Base... should probably deserve a file of it's own now. any thoughts?

10/03/06 03:54:44 changed by Tobie

  • attachment base.html.diff added.

the correct tests

(in reply to: ↑ description ) 10/03/06 04:53:20 changed by Tobie

would anyone favor addLeadingZeroes, padZero, padZeroes, rather than addLeadingZero for the method's name?

02/24/07 09:54:16 changed by Tobie

  • status changed from new to closed.
  • resolution set to wontfix.

Closes to wontfix.

Number#addLeadingZero() is superseded by Number#toPaddedString() see #7427.

I'll open up a new ticket for a non-buggy version of Number#isOdd() and Number#isEven() at some point.