Created
March 15, 2011 07:40
-
-
Save zdavatz/870425 to your computer and use it in GitHub Desktop.
index.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
EOS is Ruby heredocument.
Sample for a nested Hash:
hash = {'name' => {'resolve' => 'value'}}
hash.each do |key, value|
p value['resolve']
end