Issue #15609 has been updated by gabewild37 (Gabe Wild).

File ruby-changes.patch added

Hi, I don't know if anyone still wants this feature, but, since I wanted to get started contributing to ruby, I have implemented the following changes in my patch. Should an integer be entered into the function, the function acts like it used to. Ex: sleep(1) ==> 1, sleep(2) ==> 2. However, should a float be entered instead, the function will return a float. Ex: sleep(1.0) ==> 1.001077, sleep(2.2) ==> 2.202255. I did this by using gettimeofday() instead of time(), so the float returned is accurate to the microsecond. I also added some test code, and updated the documentation I found above the function in process.c to reflect my new changes. However, I think, instead of doing what I did, maybe making a new function or adding an optional flag could be better. Now that the return values are no longer rounded to integers, the changes in my patch could cause some backwards compatibility issues if someone is relying on rb_f_sleep to return an integer. Since I am new to both ruby and open s
 ource in general, any comments, suggestions, or improvements are appreciated. 

----------------------------------------
Feature #15609: Kernel#sleep returns Float instead of Integer
https://bugs.ruby-lang.org/issues/15609#change-80715

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
`rb_f_sleep` uses `time()` internally, so it always returns Integer even if it called with Float.

https://github.com/ruby/ruby/blob/124957566f041e5c6e8f678dfaf62cae381826dc/process.c#L4840-L4857

I think returning Float is more useful than Integer.
(But I have no real use cases now.)

---Files--------------------------------
ruby-changes.patch (2.53 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>