< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事
N :次の記事(スレッド移動)
|<:スレッドの先頭
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
On Mar 7, 2013, at 6:53 PM, charliesome (Charlie Somerville) wrote:
> There are two ways to do this
>=20
> def extend(&bk)
> singleton_class.class_eval(&bk)
> end
>=20
> or
>=20
> def extend(&bk)
> singleton_class.send(:include, Module.new(&bk))
> end
At the risk of being overly pedantic, since we're talking about =
Object#extend, I think it would be more like:
def extend(*modules, &bk)
# extend singleton_class with modules, if any
singleton_class.class_eval(&bk) if bk
end
or
def extend(module=3Dnil, &bk)
# extend singleton_class with modules, if any
singleton_class.send(:include, Module.new(&bk)) if bk
end
Which raises another question: what would be the order of extending if =
#extend is passed one or more modules *and* given a block? IOW, should =
the passed in module(s) be included first thereby giving the block the =
opportunity to override them or vice versa (or should this be explicitly =
disallowed)? I guess I'd favor the first way (include module(s) first, =
then block can override).
On the original question I tend to agree with @phluid61 that it would be =
preferable to avoid inserting an anonymous Module in the =
singleton_class's ancestors. Would having the anonymous module provide =
any advantage over not having it?
Thanks,
Dave
P.S. Why "singleton_class.send(:include, Module.new(&bk))" instead of =
just "singleton_class.include(Module.new(&bk))"? Are these somehow not =
equivalent?