ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: manga.osyo@gmail•com
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50405] [Ruby trunk Feature#14223] Refinements で定義した #to_proc が &hoge 時に呼ばれないのを緩和する提案
Date: Fri, 29 Dec 2017 06:47:26 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-69089.20171229064724.5092b18362977120@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14223.20171222164605@ruby-lang.org

Issue #14223 has been updated by osyo (manga osyo).

File refinemetns_to_proc.patch added

nobu (Nobuyoshi Nakada) wrote:
> 賛成です。

返信して頂き、ありがとうございます。

> できれば不要なインデントの変更などは混ぜないでください。

ありがとうございます。修正しました。
これで問題ないでしょうか。

----------------------------------------
Feature #14223: Refinements で定義した #to_proc が &hoge 時に呼ばれないのを緩和する提案
https://bugs.ruby-lang.org/issues/14223#change-69089

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Refinements に関する提案です。  
現行の仕様では Refinements で定義された `#to_proc` は `&hoge` 時に暗黙的に呼びだされません。  

```ruby
using Module.new {
	refine String do
		def to_proc
			proc { |it| it.send self }
		end

		def refine_method
			"X#refine_method"
		end
	end
}

def func &block
end

p "upcase".refine_method
# => "X#refine_method"

p "upcase".to_proc.call "homu"
# => "HOMU"

# Error: wrong argument type X (expected Proc) (TypeError)
func &"upcase"
```

実行結果:https://wandbox.org/permlink/j8Hhavy7LoKYjrnz


最近の傾向として `Kernel#send` や式展開時の `#to_s` などで Refinements が有効になっています。
そういう意味では `&hoge` で暗黙的に呼び出される `#to_proc` も Refinements が有効になってもよいのではないでしょうか。  
この件に関して、他の方の意見を聞かせていただけると助かります。  
また、自分で実装を書いてみたのですが『とりあえず動いている』というレベルなので、Refinements の実装に詳しい方がいればパッチもみていただけると助かります。  


---Files--------------------------------
refinemetns_to_proc.patch (3.73 KB)
refinemetns_to_proc.patch (3.26 KB)


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

  parent reply	other threads:[~2017-12-29  6:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14223.20171222164605@ruby-lang.org>
2017-12-22 16:46 ` [ruby-dev:50384] [Ruby trunk Feature#14223] Refinements で定義した #to_proc が &hoge 時に呼ばれないのを緩和する提案 manga.osyo
2017-12-26  8:39 ` [ruby-dev:50395] " nobu
2017-12-29  6:47 ` manga.osyo [this message]
2018-01-24  6:01 ` [ruby-dev:50422] " matz
2018-01-26  2:22 ` [ruby-dev:50434] " manga.osyo

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-69089.20171229064724.5092b18362977120@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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).