เมนูนำทาง
ภาษารูบี ตัวอย่างตัวอย่างโปรแกรมภาษารูบีพื้นฐาน:
# ทุกอย่างซึ่งรวมทั้งตัวอักษรเป็น[วัตถุ] อีกทั้งการเรียกใช้เมธอดไม่จำเป็นต้องมีวงเล็บตามหลัง# ดังนั้นโปรแกรมเหล่านี้จึงทำงานได้: -199.abs # 199"ruby is cool".length # 12"Rick".index ("c") # 2"Nice Day Isn't It?".split (//).uniq.sort.join # " '?DINaceinsty"
การเก็บรวบรวมโดยใช้แถวลำดับ:
a = [1, 'hi', 3.14, 1, 2, [4, 5]]a[2] # 3.14a.reverse # [[4, 5]], 2, 1, 3.14, 'hi', 1]a.flatten.uniq # [1, 'hi', 3.14, 2, 4, 5]
การเก็บรวบรวมโดยใช้แฮช:
hash = {'water' => 'wet', 'fire' => 'hot'}puts hash['fire'] # Prints: hothash.each_pair do |key, value| puts "#{key} is #{value}"end# พิมพ์: water is wet# fire is hothash.delete_if {|key, value| key == 'water'} # ลบ 'water' => 'wet'
เมนูนำทาง
ภาษารูบี ตัวอย่างใกล้เคียง
ภาษารูบีแหล่งที่มา
WikiPedia: ภาษารูบี http://www.informit.com/articles/article.asp?p=182... http://thairuby.wordpress.com/ http://www.meshplex.org/wiki/Ruby/Ruby_on_Rails_pr... http://www.ruby-lang.org http://www.ruby-lang.org/en http://www.ruby-lang.org/en/downloads/