From: shevegen@... Date: 2019-07-26T10:12:14+00:00 Subject: [ruby-core:93930] [Ruby master Feature#16021] floor/ceil/round/truncate should accept a :step argument Issue #16021 has been updated by shevegen (Robert A. Heiler). Hmm. I have mixed feelings about the proposal. I think in principle it would be ok to add more flexibility as such (e. g. :step or :by, although I think :step is a strange name). At the same time, though, this proposal makes the use of .floor() etc... a bit more complicated. People have to think more than before, such as by the example shown by shyouhei. 12.3456.floor(step: 0.0002) versus 12.3456.floor(3) (Not the same, I know, but my point is mostly that the second usage is much easier to understand from a glance alone.) I do not want to be discouraging but personally I more prefer to retain the current way only. Note that I have no really substantial opinion on the Time.now examples given above - haven't thought about its usage implications yet. I mostly refer to e. g. .floor() etc... on numbers. ---------------------------------------- Feature #16021: floor/ceil/round/truncate should accept a :step argument https://bugs.ruby-lang.org/issues/16021#change-80059 * Author: Dan0042 (Daniel DeLorme) * Status: Feedback * Priority: Normal * Assignee: * Target version: ---------------------------------------- These rounding methods currently accept a number of (decimal) digits, but a more general mechanism would allow rounding to the nearest �, multiple of 5, etc. Equivalent to e.g. `((num / step.to_f).round * step)` ``` ruby 12.3456.floor(step: 0.2) #=> 12.2 12.3456.round(step: 0.2) #=> 12.4 12.3456.floor(step: 0.2) #=> 12.4 12.3456.floor(step: 0.2) #=> 12.2 ``` IMHO this should also apply to Time#floor/round/ceil ``` ruby Time.now.floor(step: 3600) #=> current hour Time.now.round(step: 3600) #=> nearest hour Time.now.ceil(step: 3600) #=> next hour ``` We can also consider that instead of `:step` , `:by` might be quite readable. ``` ruby 12.3456.round(by: 0.2) #=> 12.4 ``` -- https://bugs.ruby-lang.org/ Unsubscribe: