Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
index.rb
def proc_resolve_search_term # :nodoc:
if(@proc_resolve_search_term.nil?)
src = <<-EOS
Proc.new { |origin|
values = {}
EOS
@resolve_search_term.each { |name, info|
src << <<-EOS
begin
values.store('#{name}', origin.#{info['resolve']})
rescue NameError
end
EOS
}
src << <<-EOS
values
}
EOS
@proc_resolve_search_term = eval(src)
end
@proc_resolve_search_term
end
@mhatakeyama

This comment has been minimized.

Copy link

@mhatakeyama mhatakeyama commented Mar 15, 2011

EOS is Ruby heredocument.

Sample for a nested Hash:
hash = {'name' => {'resolve' => 'value'}}

hash.each do |key, value|
p value['resolve']
end

@zdavatz

This comment has been minimized.

Copy link
Owner Author

@zdavatz zdavatz commented Mar 15, 2011

Strings can continue across multiple input lines, in which case they will contain newline characters. It is also possible to use here documents to express long string literals. Whenever Ruby parses the sequence <<identifier or <<quoted string, it replaces it with a string literal built from successive logical input lines. It stops building the string when it finds a line that starts with the identifier or the quoted string. You can put a minus sign immediately after the << characters, in which case the terminator can be indented from the left margin. If a quoted string was used to specify the terminator, its quoting rules will be applied to the here document; otherwise, double-quoting rules apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment