Project

General

Profile

Actions

Feature #10571

closed

Keyword arguments with local variable

Added by gogotanaka (Kazuki Tanaka) over 9 years ago. Updated over 9 years ago.

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

Description

It's kind of curiosity. As far as I searched, I couldn't get sensible reason.
Please give me information if you have free time.

class MyClass
  var = 'test'
  def my_method(kwd_var: var)
    p kwd_var
  end
end

MyClass.new.my_method
#=> NameError: undefined local variable or method `var' for #<MyClass:0x007f91520a15c8>

I've expected above code is same as below code.

class MyClass
  def my_method(kwd_var: 'test')
    p kwd_var
  end
end

MyClass.new.my_method
#=> "test"

Take your time. Thanks.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0