Ruby Programming

来源:互联网 发布:vb.net gridview 编辑:程序博客网 时间:2024/05/17 01:37
Ruby 基础

Ruby的特点如下:

1. Object Oriented
在ruby中,一切皆对象,所以的东西都可以称为对象,继承于Object, 即使是true和false变量。

2. Mixins
Ruby中有module, 类似于class, 但是module没有实例。 Module可以被mixed in 到其他的类中,相对于是对类方法的扩展。一个类可以扩展任意的module。

3. Dynamic
Ruby是动态语言, 不需要编译。可以在运行时随意改变程序中的定义,甚至可以扩展Int和String,这种特性叫做monkey patching(猴子补丁).

4. variables and scope

In Ruby , you do not need to declare the variable scope. The name of the ruby automatically determines its scope.

x :local variable$x: Global variable@x: instance variable@@x: calss variable

5. closures
Ruby中支持代码块,(在其他语言中被称为闭包)


二、脚本执行:


2.1 在terminal上执行ruby程序可以:

ruby -e "puts 'Hello world'"

#or:
ruby  hello_world.rb

#or

在irb中执行



0 0
原创粉丝点击