ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shugo@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:76315] [Ruby trunk Feature#12533][Assigned] Refinements: allow modules inclusion, in which the module can call internal methods which it defines.
Date: Fri, 08 Jul 2016 07:22:17 +0000	[thread overview]
Message-ID: <redmine.journal-59551.20160708072217.1dff6115a333b8e6@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-12533.20160629121143@ruby-lang.org

Issue #12533 has been updated by Shugo Maeda.

Status changed from Open to Assigned
Assignee set to Yukihiro Matsumoto

Matz, what do you think of this?

Local rebinding may be worth considering, but there is a trade-off.

----------------------------------------
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-59551

* Author: Tiago Cardoso
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
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/

  parent reply	other threads:[~2016-07-08  6:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-12533.20160629121143@ruby-lang.org>
2016-06-29 12:11 ` [ruby-core:76197] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines cardoso_tiago
2016-06-29 12:12 ` [ruby-core:76198] " cardoso_tiago
2016-06-29 13:32 ` [ruby-core:76205] " futu.fata
2016-06-29 13:34 ` [ruby-core:76206] " futu.fata
2016-07-08  7:22 ` shugo [this message]
2017-06-13  0:27 ` [ruby-core:81655] " shevegen
2017-09-25  7:05 ` [ruby-core:82968] " duerst
2017-09-25 12:28 ` [ruby-core:82991] " shyouhei
2017-09-26  8:34 ` [ruby-core:83019] " matz
2017-10-06 11:59 ` [ruby-core:83159] " cardoso_tiago

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-59551.20160708072217.1dff6115a333b8e6@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).