[#50354] 2.5.0で追加されたTime#atの引数について — Satoru Sakashita <sakasita@...>
坂下です。
8 messages
2017/12/16
[#50356] Re: 2.5.0で追加されたTime#atの引数について
— "Urabe, Shyouhei" <shyouhei@...>
2017/12/17
bXNlY+OBoOOBqOODn+ODquenkuOBi+ODnuOCpOOCr+ODreenkuOBi+WMuuWIpeOBjOOBpOOBi+OB
[#50357] Re: 2.5.0で追加されたTime#atの引数について
— Naotoshi Seo <sonots@...>
2017/12/18
5qiq44GL44KJ44GZ44G/44G+44Gb44KT44CC5LiA6Iis55qE44GrIG1pbGkgc2Vjb25kIOOBryBt
[#50358] Re: 2.5.0で追加されたTime#atの引数について
— "Urabe, Shyouhei" <shyouhei@...>
2017/12/18
MjAxN+W5tDEy5pyIMTjml6UgMTA6NDUgTmFvdG9zaGkgU2VvIDxzb25vdHNAZ21haWwuY29tPjoN
[#50394] [Ruby trunk Bug#14240] warn four special variables: $; $, $/ $\ — matz@...
Issue #14240 has been updated by matz (Yukihiro Matsumoto).
4 messages
2017/12/26
[#50396] Re: [Ruby trunk Bug#14240] warn four special variables: $; $, $/ $\
— Eric Wong <normalperson@...>
2017/12/26
Shouldn't English posts be on ruby-core instead of ruby-dev?
[ruby-dev:50339] [Ruby trunk Feature#4787][Closed] Integer#each_modulo(n)
From:
muraken@...
Date:
2017-12-08 08:50:29 UTC
List:
ruby-dev #50339
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/