在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、Ruby Introduction:
Ruby is "an interpreted scripting language for quick and easy object-oriented programming"。
1. Interpreted scripting language
2. Quick and easy
3.Object oriented programming
二、Variables & Constant : 1.Variables
–the scope of a local variable is one of proc{ ... }/loop{ ... }.def ... End/class ... End/module ... end
–It can be referred to from anywhere in a program. Before initialization, a global variable has the special value nil.
–Its scope is confined to whatever object self refers to.
–Same as the static member in C# language.
Note: Don’t use the Ruby keyword when define a variable.
2.Constant Definition:
e.g.: class Demo PI=3.1415 #PI=3.15214 #warning: already initialized constant PI def hello PI=3.1415 #wrong end end demo = Demo.new demo.hello
三、Comment •Single line:
#(Ctrl + /) •Multi-line
=begin … … =end
四、Numeric:
•Additional:
a=01123 #0=> Octal B=-0x23 #0X=> Hex C=+0b1010 #0=> Binary
五、Range: 1.Definition:
E.g.:
1..5 #contains: 1,2,3,4,5
1…5 #contains: 1,2,3,4
2.Methods:
e.g. a=10..20 puts a. reject{|x| x<15} puts puts a. select{|x|x<15} puts a. each{|x| puts x}
本文转自贺满博客园博客,原文链接:http://www.cnblogs.com/puresoul/archive/2012/02/20/2359245.html,如需转载请自行联系原作者。 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论