ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Ruby Tidbit: __LINE__ and heredocs

Ruby Tidbit: __LINE__ and heredocs

原创 Linux操作系统 作者:jieforest 时间:2012-09-23 10:26:51 0 删除 编辑
You’re probably familiar with __LINE__ keyword in Ruby. Wherever it’s used, it refers to the line number in the current file. It says so right here in the Ruby docs.

QUICK! What’s the output of the following code?

CODE:

#!/usr/bin/env ruby

class LineDemo
  def self.process(text, lineno)
    # do important processing on text
    puts lineno
  end
end

LineDemo.process < Here is some text on which we will do some important processing.
Here, also, is some important text to process.
TEXT
# All done!The answer is obvious. Of course, it prints 13.



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/301743/viewspace-744849/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Groovy 2.0.4 发布
请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    441
  • 访问量
    602349