Project

General

Profile

Actions

Bug #19619

closed

Numbered parameters don't work with method definition with parameters

Added by okuramasafumi (Masafumi OKURA) about 1 year ago. Updated 5 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113352]

Description

This works:

class Foo
  def bar(baz) = 'foo'
end

p Foo.new.bar('baz')

This also works:

o = Object.new
o.tap { |obj| def obj.bar(baz) = 'foo' }
p o.bar('baz')

Even this works:

o = Object.new
o.tap { def _1.bar = 'foo' }
p o.bar

But this DOESN'T work:

o = Object.new
o.tap { def _1.bar(baz) = 'foo' }
p o.bar('baz')

So, when we define a method with parameters on an instance given as numbered parameters, it doesn't work. If we change one condition (definition way, parameter existence, and so on), it works.

Updated by okuramasafumi (Masafumi OKURA) about 1 year ago

The result of the last code:

undefined method `bar' for #<Object:0x0000000108e20438> (NoMethodError)

Updated by nobu (Nobuyoshi Nakada) about 1 year ago

  • Subject changed from Endless method definition with parameters for an instance given as numbered parameters doesn't work to Numbered parameters don't work with method definition with parameters

Since this doesn't work too, endless and/or singleton method definition doesn't seem to matter.

1.times {p _1; def bar; end} #=> 0
1.times {p _1; def bar x; end} #=> nil
Actions #3

Updated by nobu (Nobuyoshi Nakada) 12 months ago

  • Status changed from Open to Closed

Applied in changeset git|b15e88e0fcccb03b9cc5e4c1478ec9b10e26c961.


[Bug #19619] Preserve numbered parameters context

Preserve numbered parameters context across method definitions

Updated by duerst (Martin Dürst) 12 months ago

@nobu (Nobuyoshi Nakada) In the above commit, I think node_new_temporary would be clearer than node_new_temporal.

Actions #5

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0