Footprint

We walk and learn


Project maintained by cellzero Hosted on GitHub Pages — Theme by mattgraham

读书笔记:Ruby基础教程第5版

Ruby version: 2.3.0

CH-01 Ruby初体验


输出方法 print、puts 和 p 的区别

irb> print "hello\t", "world", 100, "100"
hello   world100100=> nil
irb> puts  "hello\t", "world", 100, "100"
hello	
world
100
100
=> nil
irb> p     "hello\t", "world", 100, "100"
"hello\t"
"world"
100
"100"
=> ["hello\t", "world", 100, "100"]

程序文件的编码

  1. 程序的首行添加注释# encoding: 编码方式,这种注释被称为魔法注释
  2. 运行程序时,添加-E 编码方式选项,如ruby -E hello.rb

值嵌入

x = 10
y = 10
print "面积 = #{(x * y)}\n"

注释


简单语句


Back