Ruby

来自百合仙子's Wiki
跳转到导航 跳转到搜索
本页主题是一种编程语言,关于文字排版方式,见 ruby (日文)

微妙的语法

Ruby的函数调用不需要括号,同时像Javascript一样支持字面正则表达式,从而造成了以下歧义:[1]

foo = 23
def bar
  42
end

puts bar/foo   # correct
puts bar / foo # correct
puts bar /foo  # syntax error with unterminated regexp

与其类似的 CoffeeScript 会自动选择正确的那一种解释。

另一个例子:函数调用的括号和表示优先级的括号通过空白来判断[2]。此例在开启警告 -w 的情况下后者会触发一个警告。

def f(x)
  2*x
end

f(3)+1   # 7
f (3)+1  # 8

内置变量

  • $stdin, STDIN
  • $stdout, STDOUT
  • $stderr, STDERR
  • $0 , 程序名
  • ARGV , 参数列表,不含程序名

  • httpclient

参见

外部链接

教程

问题

参考资料

  1. Whitespace Sensitivity | Armin Ronacher's Thoughts and Writings
  2. CoffeeScript 也是这样;Perl 总是把这种括号理解为函数调用