Ruby syntax.ppt

21 1.2K 2
Ruby syntax.ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

môt tả

1Ruby syntax 2VariableVariables are the memory locations which holds any data to be used by any program.There are five types of variables supported by Ruby. You already have gone through a small description of these variables in previous chapter as well. These five types of variables are explained in this chapter. 3Global variableGlobal variables begin with $. Uninitialized global variables have the value nil and produce warnings with the -w option.Assignment to global variables alters global status. It is not recommended to use global variables. They make programs cryptic. 4Instance variables begin with @. Uninitialized instance variables have the value nilClass variables begin with @@ and must be initialized before they can be used in method definitions. Referencing an uninitialized class variable produces an error. Class variables are shared among descendants of the class or module in which the class variables are defined. 5Ruby ConstantsConstants begin with an uppercase letter. Constants defined within a class or module can be accessed from within that class or module, and those defined outside a class or module can be accessed globally 6Ruby operatorsArithmetric operators 7Comparison operators 8Assignment operators 9Logic operators 10If statementif conditional [then] code . [elsif conditional [then] code .] . [else code .] end [...]... 19 Hash H = Hash["a" => 100, "b" => 200] puts "#{H['a']}“ puts "#{H['b']}" 9 Logic operators 7 Comparison operators 1 Ruby syntax 16 break Terminates the most internal loop. Terminates a method with an associated block if called within the block (with the method returning nil). 3 Global variable Global variables... variables have the value nil and produce warnings with the -w option. Assignment to global variables alters global status. It is not recommended to use global variables. They make programs cryptic. 5 Ruby Constants Constants begin with an uppercase letter. Constants defined within a class or module can be accessed from within that class or module, and those defined outside a class or module can . 1Ruby syntax 2VariableVariables are the memory locations which holds any data. data to be used by any program.There are five types of variables supported by Ruby. You already have gone through a small description of these variables in

Ngày đăng: 23/08/2012, 15:51

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan