Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何共享在块内设置的变量_Ruby_Local Variables - Fatal编程技术网

Ruby 如何共享在块内设置的变量

Ruby 如何共享在块内设置的变量,ruby,local-variables,Ruby,Local Variables,我有一个方法可以执行以下操作(使用openuri) 我想知道在open的IO操作完成后,如何访问rendered_html。在块外初始化变量 def convert_html(remote_url) rendered_html = nil open(remote_url) do |file| # After some file manipulation, I do an assignment rendered_html = find_html_to_render en

我有一个方法可以执行以下操作(使用openuri)


我想知道在
open
的IO操作完成后,如何访问
rendered_html

在块外初始化变量

def convert_html(remote_url)
  rendered_html = nil
  open(remote_url) do |file|
    # After some file manipulation, I do an assignment
    rendered_html = find_html_to_render
  end
  ...
end

初始化块外部的变量

def convert_html(remote_url)
  rendered_html = nil
  open(remote_url) do |file|
    # After some file manipulation, I do an assignment
    rendered_html = find_html_to_render
  end
  ...
end

初始化块外部的变量

def convert_html(remote_url)
  rendered_html = nil
  open(remote_url) do |file|
    # After some file manipulation, I do an assignment
    rendered_html = find_html_to_render
  end
  ...
end

初始化块外部的变量

def convert_html(remote_url)
  rendered_html = nil
  open(remote_url) do |file|
    # After some file manipulation, I do an assignment
    rendered_html = find_html_to_render
  end
  ...
end