ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:51092] [Ruby master Feature#18069] `instance_exec` is just ignored when the block is originally a method
Date: Tue, 10 Aug 2021 05:33:21 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-93211.20210810053320.12651@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-18069.20210808143031.12651@ruby-lang.org>

Issue #18069 has been updated by nobu (Nobuyoshi Nakada).


A method is bound to the internal states of the receiver.
I don't think that removing the receiver from a method makes sense.

----------------------------------------
Feature #18069: `instance_exec` is just ignored when the block is originally a method
https://bugs.ruby-lang.org/issues/18069#change-93211

* Author: ttanimichi (Tsukuru Tanimichi)
* Status: Open
* Priority: Normal
----------------------------------------

I know you can't `instance_exec` a proc which is generated by `Method#to_proc` because it has its original instance's context. But, in such a case, raising `ArgumentError` would be the ideal behavior.

```ruby
f = -> (x) { a + x }

class A
  def a
    1
  end
end

A.new.instance_exec(1, &f) # => 2

class B
  def b(x)
    a + x
  end
end

proc = B.new.method(:b).to_proc
A.new.instance_exec(1, &proc) # => undefined local variable or method `a' for #<B:0x00007fdaf30480a0> (NameError)
```



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

      parent reply	other threads:[~2021-08-10  5:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08 14:30 [ruby-dev:51089] [Ruby master Bug#18069] " info
2021-08-09 19:00 ` [ruby-dev:51091] [Ruby master Feature#18069] " merch-redmine
2021-08-10  5:33 ` nobu [this message]

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-all from there: mbox

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

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

  git send-email \
    --in-reply-to=redmine.journal-93211.20210810053320.12651@ruby-lang.org \
    --to=nobu@ruby-lang.org \
    --cc=ruby-dev@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 NNTP newsgroup(s).