Ruby/Method/binding

Материал из Wiki.crossplatform.ru

Версия от 17:10, 26 мая 2010; (Обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Bind a block to a method

def aMethod
  return binding
end
the_binding = aMethod { puts "hello" }
eval "yield", the_binding                # hello



Return a binding

def aMethod
  a = "local variable"
  return binding
end
the_binding = aMethod
eval "a", the_binding   # "local variable"