Ruby
跳转到导航
跳转到搜索
本页主题是一种编程语言,关于文字排版方式,见 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
参见
外部链接
- try ruby! (in your browser)
- Rubular: a Ruby regular expression editor and tester
- Rubyxp - Ruby regular expression tester
- Rubygems 镜像 - 淘宝网
- Ruby 1.9.3和Ruby 2.0的arity的对比 - Bachue's Blog - 信仰进步,憧憬自由,热爱工作
- 将我司一个大项目的Ruby版本从1.8升级到1.9后了解到的这两个版本之间的细微差异 - Bachue's Blog - 信仰进步,憧憬自由,热爱工作
教程
- The Pragmatic Programmer's Guide
- why’s (poignant) guide to ruby
- Ruby Programming - Wikibooks, collection of open-content textbooks
- 创建你的第一个Gem
问题
参考资料
- ↑ Whitespace Sensitivity | Armin Ronacher's Thoughts and Writings
- ↑ CoffeeScript 也是这样;Perl 总是把这种括号理解为函数调用