0

I normally use class_eval do with the block but also saw examples like follows, Im trying to understand in what scenario I should use them, specifically <<-READER and <<-M

class_eval <<-READER, __FILE__ , __LINE__ + 1
  def #{sym}
    @#{sym}
  end
READER

OR

class_eval <<-M, __FILE__ , __LINE__ + 1
  def m
  end
M
user1883793
  • 4,011
  • 11
  • 36
  • 65
  • What part of this are you asking about? The HEREDOC style `<<` or the use of `class_eval` in general? – tadman Mar 06 '18 at 21:55
  • 1
    Hi @tadman do block vs <<-READER and <<-M – user1883793 Mar 06 '18 at 22:44
  • 1
    Possible duplicate of [What does class\_eval <<-"end\_eval", \_\_FILE\_\_, \_\_LINE\_\_ mean in Ruby?](https://stackoverflow.com/questions/2496102/what-does-class-eval-end-eval-file-line-mean-in-ruby) – Rustik Mar 07 '18 at 07:24
  • `eval` takes either a string or a block of code via `do ... end` or `{ ... }`. The string version can be specified any way a string can, including HEREDOC. – tadman Mar 07 '18 at 17:04

0 Answers0