[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: [ruby-core:76207] [Ruby trunk Bug#12535][Rejected] are there 2 sleep methods defined?
From: nobu () ruby-lang ! org
Date: 2016-06-30 0:27:42
Message-ID: redmine.journal-59423.20160630002742.b0ce7eb51395b27c () ruby-lang ! org
[Download RAW message or body]
Issue #12535 has been updated by Nobuyoshi Nakada.
Description updated
Status changed from Open to Rejected
No.
You are prepending the method on 2 different **objects**, `main` and `Kernel`.
----------------------------------------
Bug #12535: are there 2 sleep methods defined?
https://bugs.ruby-lang.org/issues/12535#change-59423
* Author: Tiago Cardoso
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v:
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
I'm updating this gem which "patches" the sleep method to use prepend, as I wanted to \
drop support to ruby < 2.0 . (previous implementation was using alias method chain \
like solution)
So I came across this funny behaviour:
```ruby
module AlternativeSleep
def sleep(*)
puts "going to sleep now..."
super
end
end
class << self
prepend AlternativeSleep
end
class << Kernel
prepend AlternativeSleep
end
puts "these are the locations..."
puts Kernel.method(:sleep)
puts method(:sleep)
puts "now to work. if you see the going to sleep message only once, there's your bug"
Kernel.sleep 1
sleep 1
```
In order to make sleep work in both cases, I have to do those 2 prepends. Try to \
comment one of them, and you'll see that one of them will always work.
I'm led to believe that sleep method has two implementations, although that doesn't \
seem to make sense. Could you provide with some insight?
When I was using the alias-method-chain example, I was including in the main object, \
as `main#sleep` somehow seemed to land in `Kernel.sleep` (?) .
--
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>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic