From the Ruby_Newbie Guide to Symbols:
Author is trying to show a simplified implementation of the attr_writer method.
#!/usr/bin/env ruby
def make_me_a
-
It's a heredoc. From the "Here Documents" documentation:
If you are writing a large block of text you may use a “here document”
or “heredoc”:
expected_result = <<HEREDOC
This would contain specially formatted text.
That might span many lines
HEREDOC
The heredoc starts on the line following <<HEREDOC
and ends with the
next line that starts with HEREDOC
. The result includes the ending
newline.
讨论(0)
-
It's a multi line string. The code evaluates code embedded inside string. More on multi line strings:
http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html
P.S. Using eval is not recommended, alternatives - yield, instance_eval, class_eval.
讨论(0)
- 热议问题