1. The conversion between integers, floating-point numbers, and strings in Ruby
The classes of ruby integers, floating-point numbers, and strings provide to_i,to_f,to_s three methods for converting integers, converting them to floating-point numbers, and converting them into strings.
2. Array traversal
Example 1:
a=['a','b','C']a.each {|x|puts X}
Example 2:ps=["EMSD","XIO","DPAD","ISD","DSSD","ASD","VCE","RSA","IIG","N /A"]ps.each{|x| Innovationproduct.create (:bu=>x,:innovation_product_id=>0)}
Example 3:products=Innovationproduct.get_products_by_bu (BU) productsarray=array.new forJinchProducts Productsarray.push (j.product) End
3. If Judgment statement
Example 1:
A=1if a==1 1 #打印1elsif a==2 2else 3 End
Example 2:
A=false if a 1 elsif!a 2 # Print 2 Else 3 end
4, puts and print difference: Puts line, print does not wrap.
5. How to get input from the command line in Ruby: Gets, the input variable is stored in $_
" Please enter the temperature: " gets #输入 "AAABBBCCC" puts $_ #输出 "AAABBBCCC"
6. Symbolic symbol (:)
In Ruby, Symbol denotes "name", such as the name of the string, the name of the identifier. The way to create a Symbol object is to precede the name or string with a colon:
Create a Symbol object, for example:
: Foo:test
: "ABC" #结果是: "I am a Boy"
String is a string, why do you have the name of the string? This is because a string is also an object in Ruby, a string object. Both the structure and the operation and the Symbol object are different.
7, in Ruby each object has a unique object identifier (Identifier), you can use the Object_ID method to get an identifier for an object.
Example: puts:foo.object_id
Ruby Usage Summary (EMC)