ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: andrew.kozin@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:69674] [Ruby trunk - Bug #11283] Block assigned implicitly
Date: Fri, 19 Jun 2015 05:49:52 +0000	[thread overview]
Message-ID: <redmine.journal-53034.20150619054951.fb41dfc68c7e3fb3@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11283.20150618153632@ruby-lang.org

Issue #11283 has been updated by Andrew Kozin.


Not, in my examples (from the initial post) it does not do that, but something different. Namely, it doesn't assigning a **new** proc (that would be OK)

Instead, the interpreter it looks around in search **what else** it could use when I doesn't send a proc, then takes what it found somewhere and pushes it to the method.

MRI doesn't let me decide whether the method should be called without a proc (that should be interpreted as asking for `Proc.new`, as in your example).
**This** is the bug, not the way it works out the `:define_method` call.

----------------------------------------
Bug #11283: Block assigned implicitly
https://bugs.ruby-lang.org/issues/11283#change-53034

* Author: Andrew Kozin
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 1.9.3, 2.0, 2.1, 2.2, ruby-head
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
That is how it works:

    module Test
      def self.build(&block)
        klass = Class.new(Object)
        klass.__send__(:define_method, :foo)
        klass.__send__(:define_method, :bar)
        klass
      end
    end

    Tested = Test.build { :foo }
    # warning: tried to create Proc object without a block
    # => Tested
    Tested.new.foo
    # => :foo
    Tested.new.bar
    # => :foo

The block is assigned to all calls to `:define_method` via `Object#__send__` implicitly, while it wasn't asked to.

The behaviour is tested under MRI 1.9.3, 2.0, 2.1, 2.2, ruby-head. It doesn't occur under rbx-2 and jruby (1.7, 9.0.0.0).

For the context look at this thread https://github.com/mbj/mutant/issues/356



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

  parent reply	other threads:[~2015-06-19  5:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11283.20150618153632@ruby-lang.org>
2015-06-18 15:36 ` [ruby-core:69655] [Ruby trunk - Bug #11283] [Open] Block assigned implicitly andrew.kozin
2015-06-18 15:39 ` [ruby-core:69656] [Ruby trunk - Bug #11283] " andrew.kozin
2015-06-18 15:46 ` [ruby-core:69657] " andrew.kozin
2015-06-18 15:48 ` [ruby-core:69658] " andrew.kozin
2015-06-18 15:49 ` [ruby-core:69659] " andrew.kozin
2015-06-18 15:51 ` [ruby-core:69660] " andrew.kozin
2015-06-18 15:52 ` [ruby-core:69661] " andrew.kozin
2015-06-18 19:11 ` [ruby-core:69664] " funny.falcon
2015-06-18 19:31 ` [ruby-core:69665] " andrew.kozin
2015-06-18 21:56 ` [ruby-core:69667] " 0x0dea+redmine
2015-06-18 22:45 ` [ruby-core:69669] " andrew.kozin
2015-06-19  2:25 ` [ruby-core:69673] " 0x0dea+redmine
2015-06-19  5:49 ` andrew.kozin [this message]
2015-06-30  3:25 ` [ruby-core:69789] " usa
2015-08-14  7:50 ` [ruby-core:70385] " nagachika00
2015-08-17  8:55 ` [ruby-core:70421] " usa

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-53034.20150619054951.fb41dfc68c7e3fb3@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).