Peter Piper Peter Piper - 1 year ago 74
Ruby Question

What does the `<<` (double less than) mean without an argument?

I found this inside a method I want to override in the formtastic Gem. The method looks like:

def to_html
input_wrapping do
hidden_field_html <<

What does the
do on the third line? I know what it does with Arrays but here I have no idea.

Answer Source

You can read it like this:

hidden_field_html << label_with_nested_checkbox

label_with_nested_checkbox is the argument being concatenated onto the end of hidden_field_html - they've split it over two lines for 'clarity'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download