* [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n)
@ 2011-05-27 4:21 Kenta Murata
2011-06-29 4:33 ` [ruby-dev:43989] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n) Yukihiro Matsumoto
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Kenta Murata @ 2011-05-27 4:21 UTC (permalink / raw)
To: ruby developers list
Issue #4787 has been reported by Kenta Murata.
----------------------------------------
Bug #4787: Integer#each_modulo(n)
http://redmine.ruby-lang.org/issues/4787
Author: Kenta Murata
Status: Open
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.3dev (2011-05-27 trunk 31745) [x86_64-darwin10.7.0]
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
The following code is an example use of the feature:
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
I make an implementation in C, and attach the patch for that.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:43989] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
@ 2011-06-29 4:33 ` Yukihiro Matsumoto
2011-07-16 23:42 ` [ruby-dev:44121] " Thomas Sawyer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Yukihiro Matsumoto @ 2011-06-29 4:33 UTC (permalink / raw)
To: ruby developers list
Issue #4787 has been updated by Yukihiro Matsumoto.
Target version changed from 1.9.3 to 1.9.x
----------------------------------------
Feature #4787: Integer#each_modulo(n)
http://redmine.ruby-lang.org/issues/4787
Author: Kenta Murata
Status: Open
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 1.9.x
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
The following code is an example use of the feature:
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
I make an implementation in C, and attach the patch for that.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:44121] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
2011-06-29 4:33 ` [ruby-dev:43989] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n) Yukihiro Matsumoto
@ 2011-07-16 23:42 ` Thomas Sawyer
2012-10-25 11:16 ` [ruby-dev:46268] [ruby-trunk " yhara (Yutaka HARA)
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Sawyer @ 2011-07-16 23:42 UTC (permalink / raw)
To: ruby developers list
Issue #4787 has been updated by Thomas Sawyer.
Why not just let #modulo/#divmod take a block, rather than define a new method?
----------------------------------------
Feature #4787: Integer#each_modulo(n)
http://redmine.ruby-lang.org/issues/4787
Author: Kenta Murata
Status: Open
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 1.9.x
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
The following code is an example use of the feature:
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
I make an implementation in C, and attach the patch for that.
--
http://redmine.ruby-lang.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:46268] [ruby-trunk - Feature #4787] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
2011-06-29 4:33 ` [ruby-dev:43989] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n) Yukihiro Matsumoto
2011-07-16 23:42 ` [ruby-dev:44121] " Thomas Sawyer
@ 2012-10-25 11:16 ` yhara (Yutaka HARA)
2016-06-07 5:35 ` [ruby-dev:49646] [Ruby trunk Feature#4787] Integer#each_modulo(n) nobu
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: yhara (Yutaka HARA) @ 2012-10-25 11:16 UTC (permalink / raw)
To: ruby developers list
Issue #4787 has been updated by yhara (Yutaka HARA).
Target version changed from 2.0.0 to next minor
----------------------------------------
Feature #4787: Integer#each_modulo(n)
https://bugs.ruby-lang.org/issues/4787#change-31543
Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
The following code is an example use of the feature:
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
I make an implementation in C, and attach the patch for that.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:49646] [Ruby trunk Feature#4787] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
` (2 preceding siblings ...)
2012-10-25 11:16 ` [ruby-dev:46268] [ruby-trunk " yhara (Yutaka HARA)
@ 2016-06-07 5:35 ` nobu
2016-06-07 6:18 ` [ruby-dev:49647] " duerst
2017-12-08 8:50 ` [ruby-dev:50339] [Ruby trunk Feature#4787][Closed] Integer#each_modulo(n) muraken
5 siblings, 0 replies; 7+ messages in thread
From: nobu @ 2016-06-07 5:35 UTC (permalink / raw)
To: ruby-dev
Issue #4787 has been updated by Nobuyoshi Nakada.
Description updated
----------------------------------------
Feature #4787: Integer#each_modulo(n)
https://bugs.ruby-lang.org/issues/4787#change-59040
* Author: Kenta Murata
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
```ruby
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
```
The following code is an example use of the feature:
```ruby
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
```
I make an implementation in C, and attach the patch for that.
---Files--------------------------------
each_modulo.patch (3.91 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:49647] [Ruby trunk Feature#4787] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
` (3 preceding siblings ...)
2016-06-07 5:35 ` [ruby-dev:49646] [Ruby trunk Feature#4787] Integer#each_modulo(n) nobu
@ 2016-06-07 6:18 ` duerst
2017-12-08 8:50 ` [ruby-dev:50339] [Ruby trunk Feature#4787][Closed] Integer#each_modulo(n) muraken
5 siblings, 0 replies; 7+ messages in thread
From: duerst @ 2016-06-07 6:18 UTC (permalink / raw)
To: ruby-dev
Issue #4787 has been updated by Martin Dürst.
This only gives the 'mod' part. Why not extend this to get both the 'div' part and the 'mod' part back (see also comment #4)?
And why not allow an array of integers as an argument? Some conventions for displaying large numbers with separators are not uniform, in particular in India (see https://en.wikipedia.org/wiki/Indian_numbering_system).
----------------------------------------
Feature #4787: Integer#each_modulo(n)
https://bugs.ruby-lang.org/issues/4787#change-59042
* Author: Kenta Murata
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
```ruby
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
```
The following code is an example use of the feature:
```ruby
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
```
I make an implementation in C, and attach the patch for that.
---Files--------------------------------
each_modulo.patch (3.91 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-dev:50339] [Ruby trunk Feature#4787][Closed] Integer#each_modulo(n)
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
` (4 preceding siblings ...)
2016-06-07 6:18 ` [ruby-dev:49647] " duerst
@ 2017-12-08 8:50 ` muraken
5 siblings, 0 replies; 7+ messages in thread
From: muraken @ 2017-12-08 8:50 UTC (permalink / raw)
To: ruby-dev
Issue #4787 has been updated by mrkn (Kenta Murata).
Status changed from Assigned to Closed
This was resolved by #12447.
----------------------------------------
Feature #4787: Integer#each_modulo(n)
https://bugs.ruby-lang.org/issues/4787#change-68229
* Author: mrkn (Kenta Murata)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
I suggest a new feature of Integer to enumerate by iterated Integer#modulo.
An example implementation in Ruby is the following code:
```ruby
class Integer
def each_modulo(n)
raise ArgumentError, "argument must be an Integer" unless n.is_a? Integer
raise ArgumentError, "argument must be larger than 1" if n <= 1
return Enumerator.new(self, :each_modulo, n) unless block_given?
q = self
while q > 0
q, r = q.divmod(n)
yield(r)
end
end
end
p 133.each_modulo(3).to_a #=> [1, 2, 2, 1, 1]
```
The following code is an example use of the feature:
```ruby
class Integer
def each_thousand_separation
each_modulo(1000)
end
def thousand_separated_string(sep=',')
each_thousand_separation.map(&'%03d'.method(:%)).inject{|s, n| n + sep + s }
end
end
p 100_000_000_200.thousand_separated_string #=> "100,000,000,200"
```
I make an implementation in C, and attach the patch for that.
---Files--------------------------------
each_modulo.patch (3.91 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-12-08 8:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-27 4:21 [ruby-dev:43586] [Ruby 1.9 - Bug #4787][Open] Integer#each_modulo(n) Kenta Murata
2011-06-29 4:33 ` [ruby-dev:43989] [Ruby 1.9 - Feature #4787] Integer#each_modulo(n) Yukihiro Matsumoto
2011-07-16 23:42 ` [ruby-dev:44121] " Thomas Sawyer
2012-10-25 11:16 ` [ruby-dev:46268] [ruby-trunk " yhara (Yutaka HARA)
2016-06-07 5:35 ` [ruby-dev:49646] [Ruby trunk Feature#4787] Integer#each_modulo(n) nobu
2016-06-07 6:18 ` [ruby-dev:49647] " duerst
2017-12-08 8:50 ` [ruby-dev:50339] [Ruby trunk Feature#4787][Closed] Integer#each_modulo(n) muraken
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).