ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:48610] [ruby-trunk - Feature #10355] [Open] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
@ 2014-10-10  3:32 ` tagomoris
  2014-10-10  3:56 ` [ruby-dev:48611] [ruby-trunk - Feature #10355] " tagomoris
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: tagomoris @ 2014-10-10  3:32 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been reported by Satoshi TAGOMORI.

----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355

* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
Module#include? を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

<pre>
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
</pre>



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-dev:48611] [ruby-trunk - Feature #10355] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
  2014-10-10  3:32 ` [ruby-dev:48610] [ruby-trunk - Feature #10355] [Open] Feature request: Module#prepended?(mod) tagomoris
@ 2014-10-10  3:56 ` tagomoris
  2014-10-10  4:15 ` [ruby-dev:48612] " tagomoris
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: tagomoris @ 2014-10-10  3:56 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been updated by Satoshi TAGOMORI.


ある機能が prepend によって追加されているかどうかを調べたいときに Module#include? では不十分です。
継承関係の親クラスにおいて prepend されたモジュールのメソッドは、子クラスでも定義が存在する場合、実際には呼び出されません。

<pre><code class="ruby">
module P
  def myname
    str = super
    "p" + str
  end
end

class X
  def myname
    "x"
  end
  prepend P
end

X.include?(P) #=> true
X.new.myname #=> "px"

class Y < X
  def myname
    "y"
  end
end

Y.include?(P) #=> true
Y.new.myname #=> "y" # without prepended method
</code></pre>

以下の方法で調べることは可能ですが冗長な上、Moduleクラスへのモンキーパッチも
通常の用途ではためらわれるため、標準でサポートされていると助かります。

<pre><code class="ruby">
class Module
  def prepended?(mod)
    self.ancestors.include?(mod) && self.ancestors.index(mod) < self.ancestors.index(self)
  end
end
</code></pre>

----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355#change-49333

* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
Module#include? を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

<pre>
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
</pre>



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-dev:48612] [ruby-trunk - Feature #10355] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
  2014-10-10  3:32 ` [ruby-dev:48610] [ruby-trunk - Feature #10355] [Open] Feature request: Module#prepended?(mod) tagomoris
  2014-10-10  3:56 ` [ruby-dev:48611] [ruby-trunk - Feature #10355] " tagomoris
@ 2014-10-10  4:15 ` tagomoris
  2014-10-10  4:34 ` [ruby-dev:48613] [ruby-trunk - Feature #10355] [Feedback] " nobu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: tagomoris @ 2014-10-10  4:15 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been updated by Satoshi TAGOMORI.


特定メソッドの出力のフィルタをprependによって実現したい場合、親クラスで既にprependされていても子クラスでメソッド定義が上書きされればprependが実際には効かないことになります。
このような状態が起きてないかどうかを調べる必要がある(起きていればprependしなおす)、というケースで Module#prepended? 相当の機能が必要となります。

フレームワークなどの記述において、DI等で挿入されたオブジェクトの機能を調べてコントロールする用途などで必要です。


----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355#change-49334

* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
Module#include? を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

<pre>
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
</pre>



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-dev:48613] [ruby-trunk - Feature #10355] [Feedback] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2014-10-10  4:15 ` [ruby-dev:48612] " tagomoris
@ 2014-10-10  4:34 ` nobu
  2014-10-10  5:36 ` [ruby-dev:48614] [ruby-trunk - Feature #10355] " tagomoris
  2014-10-10  7:16 ` [ruby-dev:48615] " tagomoris
  5 siblings, 0 replies; 6+ messages in thread
From: nobu @ 2014-10-10  4:34 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been updated by Nobuyoshi Nakada.

Description updated
Category set to core
Status changed from Open to Feedback
Assignee set to Yukihiro Matsumoto
Target version set to current: 2.2.0

このメソッドに反対なわけではないですが、メソッド定義が上書きされているかどうかを調べたいのであれば、`UnboundMethod#owner`などを使うほうがいいのではないでしょうか。

----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355#change-49336

* Author: Satoshi TAGOMORI
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.0
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
`Module#include?` を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

~~~ruby
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
~~~



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-dev:48614] [ruby-trunk - Feature #10355] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2014-10-10  4:34 ` [ruby-dev:48613] [ruby-trunk - Feature #10355] [Feedback] " nobu
@ 2014-10-10  5:36 ` tagomoris
  2014-10-10  7:16 ` [ruby-dev:48615] " tagomoris
  5 siblings, 0 replies; 6+ messages in thread
From: tagomoris @ 2014-10-10  5:36 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been updated by Satoshi TAGOMORI.


メソッド定義が上書きされているかどうかを調べたいというより、誰がownerでもいいけど確実にprependされていてほしい、という方が要求として正確なように思います。

----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355#change-49338

* Author: Satoshi TAGOMORI
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.0
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
`Module#include?` を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

~~~ruby
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
~~~



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-dev:48615] [ruby-trunk - Feature #10355] Feature request: Module#prepended?(mod)
       [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2014-10-10  5:36 ` [ruby-dev:48614] [ruby-trunk - Feature #10355] " tagomoris
@ 2014-10-10  7:16 ` tagomoris
  5 siblings, 0 replies; 6+ messages in thread
From: tagomoris @ 2014-10-10  7:16 UTC (permalink / raw
  To: ruby-dev

Issue #10355 has been updated by Satoshi TAGOMORI.


提案する名前について `prepended?` は正しくありませんでした。`prepend?` が正しいです。訂正します。

----------------------------------------
Feature #10355: Feature request: Module#prepended?(mod)
https://bugs.ruby-lang.org/issues/10355#change-49339

* Author: Satoshi TAGOMORI
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.0
----------------------------------------
あるモジュール X に対してモジュール P1 がprependされているかどうかを調べる方法があると嬉しく思います。
`Module#include?` を使うと継承関係に含まれているかどうかはわかりますが、それが対象モジュールに対してprependされたものかは分かりません。

~~~ruby
module P1; end
module P2; end

class X
  prepend P1
end
class Y< X
  prepend P2
end

X.include?(P1) #=> true
Y.include?(P2) #=> true
Y.include?(P1) #=> true

# I want
X.prepended?(P1) #=> true
Y.prepended?(P2) #=> true
Y.prepended?(P1) #=> false
~~~



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-10  7:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-10355.20141010033216@ruby-lang.org>
2014-10-10  3:32 ` [ruby-dev:48610] [ruby-trunk - Feature #10355] [Open] Feature request: Module#prepended?(mod) tagomoris
2014-10-10  3:56 ` [ruby-dev:48611] [ruby-trunk - Feature #10355] " tagomoris
2014-10-10  4:15 ` [ruby-dev:48612] " tagomoris
2014-10-10  4:34 ` [ruby-dev:48613] [ruby-trunk - Feature #10355] [Feedback] " nobu
2014-10-10  5:36 ` [ruby-dev:48614] [ruby-trunk - Feature #10355] " tagomoris
2014-10-10  7:16 ` [ruby-dev:48615] " tagomoris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).