zoukankan      html  css  js  c++  java
  • Ruby多行字符串,begin/end语句、注释

    #!/usr/bin/ruby

    #puts "Hello ,Ruby!";

    print <<EOF #多行字符串 以<<开头 紧接着为结束字符串标识声明 并且定义的结束标识符必须在新的一行顶格出现才能终止

        这是第一种方式创建here document

        多行字符串 EOF

    EOF

    print <<"EOF"; #与上面相同

        这是第二种方式创建here document;

        多行字符串

    EOF

    print <<'EOC'

            echo hi there

            echo lo there

    EOC

    print <<"foo",<<"bar"

            i said foo

    foo

            i said bar.

    bar

    #注释  可以以哈希字符开头一行  也可以在同一行后一个语句或表达式

    #this is a comment .Just ignore me

    BEGIN{ #begin语句 闭包内的code在程序执行时首先执行

        

        puts "This is main Ruby Program"

        

    }

    END{#end语句 闭包内code在程序最后执行

        puts "This is end of this Ruby Program"

        

    }

    =begin

    另一种多行注释形式

    同时隐藏几行注释

    =end

  • 相关阅读:
    实验4
    实验3
    第七章例7-14
    第七章例7-13
    第七章例7-12
    第七章例7-11
    第七章例7-10
    diyiti
    disanti
    第二题
  • 原文地址:https://www.cnblogs.com/ToBeTheOne/p/5728064.html
Copyright © 2011-2022 走看看