What is <<- in ruby?

前端 未结 2 618
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 06:03

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         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 06:31

    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.

提交回复
热议问题