[#83107] Alias Enumerable#include? to Enumerable#includes? — Alberto Almagro <albertoalmagro@...>

Hello,

9 messages 2017/10/04

[ruby-core:83159] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.

From: cardoso_tiago@...
Date: 2017-10-06 11:59:14 UTC
List: ruby-core #83159
Issue #12533 has been updated by chucke (Tiago Cardoso).


How about redefining `#include` in the context of refine as what would be expected of the new `#inject` method? I get that the semantics of module inclusion differ in both context regarding inheritance hierarchy order, but I'm still thinking from the user perspective: "if I do it, what do I expect to happen?".

From this user perspective, I'd prefer an `#include` method which does what I expect, instead of yet another method (`#inject`) that I have to learn.

But there might be other implications. I'm fine with whichever proposal which makes refinements more usable for meta-programming. 

----------------------------------------
Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. 
https://bugs.ruby-lang.org/issues/12533#change-67095

* Author: chucke (Tiago Cardoso)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Right now this isn't possible:

~~~ruby
module Extensions
  def vegetables ; potatoe ; end
  def potatoe ; "potatoe" ; end
end

module Refinary
  refine String do
  # this doesn't work
  include Extensions
  # this would work...
  # def vegetables ; potatoe ; end
  # def potatoe ; "potatoe" ; end
  end
end

using Refinary

puts "tomatoe".vegetables

#=> in <main>': undefined method 'vegetables' for "tomatoe":String
~~~

Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). 

According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. 



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

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

In This Thread

Prev Next