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