Project

General

Profile

Actions

Bug #11005

closed

why block bind can not be in my_method2

Added by gagahappy (Happy GaGa) about 9 years ago. Updated about 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.1.2, 2.2.1
[ruby-core:<unknown>]

Description

class MyClass
  def my_method1
    nice_name = "Lucy"
    @proc = lambda {|say| "#{say}, #{nice_name}"}
    nice_name = "Sophy"
    puts @proc.call 'Hi' # => Hi, Sophy

    nice_name = "Oleg"
    puts @proc.call 'Hi' # => Hi, Oleg
  end

  def my_method2
    nice_name = 'Han'  
    puts @proc.call 'Hey' # => Hey, Oleg **#Expect is "Hey, Han"**** 
  end
end

obj = MyClass.new
obj.my_method1 
obj.my_method2
Actions #1

Updated by matz (Yukihiro Matsumoto) about 9 years ago

  • Status changed from Open to Rejected

@proc binds the scope of my_method1, not of my_method2.
We are not going to change that.

Matz.

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 9 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0