==
Returns an HTML block tag of type name surrounding the content.
==
Ok, not too helpful unless you understand the subtleties of css/html
speak. But the docs provide some examples that should help clarify
things:
content_tag(:p, "Hello world!")
# => <p>Hello world!</p>
Presumably, the html is a String--the return value doesn't look like a
number or a method.
As for how blocks work: a block is really just a function. You write a
block in your code immediately after calling a method, and the method
captures the block in a variable. Then at some point the method calls
the block. Here is an example:
def some_method(str, &func)
if block_given?
puts func.call(str)
else
puts str
end
end
some_method("John") do |name|
"Hello #{name}"
end
--output:--
Hello John
The block is this part:
do |name|
"Hello #{name}"
end
which can also be written as:
{ |name| "Hello #{name"}
--
Posted via http://www.ruby-forum.com/.
Yes, that's all correct. + is just a strange name for a ruby method.
If you write:
"hello" + " world"
That is equivalent to:
"hello".+("world")
That may look confusing but suppose you were calling a method like
split:
"hello,world".split(",")
That is the exact same format as the + method call:
obj.meth_name(arg)
> But
> what it does with blocks of html
>
That's not what the docs mean about the return value of content_tag. In
html, the term 'block tag' has a specific meaning. The docs aren't
describing the return value, which is actually a String. Good docs list
the return type of a method because that is one of the most important
things you can know about a method in addition to the argument types.