Ruby中一切皆對象,任何對象都有一個布爾值返回值(Boolean value)
nil
puts "Hello world"
這個語句返回Boolean
值nil
,並且按照功能輸出字符串Hello world
;
PS C:\Users\Administrator\RubyCode> irb --simple-prompt
>> puts "Hello world"
Hello world
=> nil
>> if puts "Hello world"
>> puts "You can't see this"
>> end
Hello world
=> nil
false or true
1 == 2
返回Boolean
值false
;if...end
代碼塊整體返回Boolean
值nil
;
PS C:\Users\Administrator\RubyCode> irb --simple-prompt
>> if 1 == 2
>> puts " One is equal to Two"
>> end
=> nil
>> 1 == 2
=> false
>> 1 != 2
=> true
extra #{}
#{} 裏面使用佔位符輸出浮點數值如下(還自動給四捨五入了):
PS C:\Users\Administrator\RubyCode> more ex2.rb
# string output
h_w = 'hello world'
puts "This is #{h_w}"
# number output
float_num = 1.230567
puts "#{"num is %.3f" %float_num}"
PS C:\Users\Administrator\RubyCode> ruby ex2.rb
This is hello world
num is 1.231
reference
《The Well-Grounded Rubyist, Second Edition》
(https://www.manning.com/books/the-well-grounded-rubyist-second-edition)
2.2. Crafting an object: The behavior of a ticket
どんだけ~
η゛
∧ ∧(≡)
(´∀`) /
⊂ ノ
(つ ノ
(ノ
http://emoji.vis.ne.jp/dondake.htm