[#49675] Request to update LEGAL file for zlib, UCD license — Jun Aruga <jaruga@...>
こんにちは。有賀と申します。
10 messages
2016/06/20
[#49678] Re: Request to update LEGAL file for zlib, UCD license
— Jun Aruga <jaruga@...>
2016/06/21
ご回答、そして+1のご意見ありがとうございます。
[#49683] Re: Request to update LEGAL file for zlib, UCD license
— Martin J. Dürst <duerst@...>
2016/06/22
On 2016/06/22 00:15, Jun Aruga wrote:
[ruby-dev:49646] [Ruby trunk Feature#4787] Integer#each_modulo(n)
From:
nobu@...
Date:
2016-06-07 05:35:22 UTC
List:
ruby-dev #49646
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/