Consider adding Sub-Includes as in include Foo::bar
On IRC someone asked a nice question:
<arup_r> If I write
class Foo; include Enumerable; endThis code include all methods from
Enumerable. But suppose I want to include
#any?.. What's the way to include only required methods ?
This prompted me to write this.
What if ruby would allow us to include just singular methods?
And so forth, so that we could cherry-pick what we want.
This is already possible in some projects, like facets.
But I think they solve it by splitting up the whole
stuff into individual files, and then including
I think it would be nicer if include itself would
support a scope-mechanic.
Updated by nobu (Nobuyoshi Nakada) almost 6 years ago
- Tracker changed from Bug to Feature
- Description updated (diff)
- Status changed from Open to Feedback
You can achieve it by "method transplanting".
class Foo define_method(:any?, Enumerable.instance_method(:any?)) end
Wrapper method like
Module#mix may help you.
It has been removed finally, you can construct