Ruby 學習筆記(一)

來源:互聯網
上載者:User

Ruby 學習筆記

參考書--why’s (poignant) guide to ruby :CSDN資源ruby中的資料類型和其他基本操作資訊variables 

any plain,lowercase word is a variable in ruby
例如 x,y,banana2,phone_a_quail

numbers

a series of digits which can start with a plus or minus sign
例如 1,23,-10000

strings

any sort of character surrounded by quotes
例如 "sealab" ,'2021'

symbols

words that look just like variables,start with a colon
例如 :a , :b :ponce_de_leon

constants

words like variables,but they are capitalized
例如 Time, Array,Bunny_Lake_is_Missing

methods

attached to the end od variables and constants by a dot
例如 front_door.open 
front_door.is_open? 用來測試使用 Door_test_to_see_if_its_open

method arguments

attached to the end of a method, usually surrounded by parenthese and separated by commas
例如 front_door.paint(3, :red) 
front_door.paint(3,:red).dry(30).close() 函數可以鏈式執行

class methods

usually attached after variables and constants, used a double colon
例如 Door::new(:oak)

global variables

variables which begin with a dollar sign
例如 $x, $1, $chunky

instance variables

variables which begin with an at symbol 
例如 @x ,@y ,@only_the_chunk

class variables

variables which begin with double at symbols
例如 @@x, @@y,@@i_will
class variables give an attribute to many related objects in ruby

blocks

any code surrounded by curly braces 
例如 2.times{print "yes. i am a student, but never agian"}
loop do 
print "much better"
print "i am better"
end 

block arguments

a set of variables surrounded by pipe characters and separated by commas
例如 |x|, |y| ,|up ,down|
使用方法 at the beginning of a block 例如{|x, y| x+y}

ranges

two values surrounded by parentheses and separated by an ellipsis
例如 (1..3) 表示從1到3的數,('a'..'z')表示小寫字母
 if a third dot is used, the last value in the range is exclueded
 例如(0...5) 表示從0到4

arrays

a list surrounded by square brackets and separated by commas
例如 {1,2,3} ,{'coat','mittens','snowboard'}

hashes

a dictionary surrounded by curly braces,use an arrow like an equals sign
例如 {'a'=> 'aardvarx','b'=>'badgar'} 

regular expressions

a set of characters surrounded by slashes
例如 /ruby/,/[0-9]+/, /^\d{3}-\d{3}-\d{4}/

operators

這裡僅列出不熟悉的

** =~ !~===.....
<=>

全部見圖

keywords

這裡僅列出不熟悉的

alias BEGIN(與begin 不同) elsif END(與end不同) ensure module nil(應該與NULL差不多) rescue retry self  yield

全部見圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.