您的位置:首页 > 编程语言 > Ruby

[Ruby笔记]2. ruby基础的基础: irb --simple-prompt / puts print p/ false nil

2016-05-16 02:09 423 查看

irb –simple-prompt

PS C:\Users\Administrator> irb
irb(main):001:0> exit()

PS C:\Users\Administrator> irb --simple-prompt
>> exit()
PS C:\Users\Administrator>


simple模式更“清爽”

puts print p

创建两个变量x、y

PS C:\Users\Administrator> irb --simple-prompt
>> x = "hello"
=> "hello"
>> y = "world"
=> "world"


p 无视了转义符号

puts 输出自带换行,print给啥写啥不带换行

>> p x + " \n " + y
"hello \n world"
=> "hello \n world"

>> print x + " \n " + y
hello
world=> nil #注意:这里没有换行就输出了nil

>> puts x + " \n " + y
hello
world
=> nil #注意:这里换行后再输出了nil


false nil

Ruby中 除了 [b]false 以及 nil[/b] 其余在条件判断中都是true的作用

0 (Zero零)在ruby中也是true

PS C:\Users\Administrator\RubyCode> ls

目录: C:\Users\Administrator\RubyCode

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         2016/5/16      2:00         48 ex111.rb

PS C:\Users\Administrator\RubyCode> more ex111.rb
if 0
puts "true"
elsif
puts "false"
end

PS C:\Users\Administrator\RubyCode> ruby ex111.rb
true


Reference

> 《The Well-Grounded Rubyist, Second Edition》
(https://www.manning.com/books/the-well-grounded-rubyist-second-edition)
1.1.1. A Ruby syntax survival kit

>       /ヽ       /ヽ  
      /  ヽ      /  ヽ 
     /     ヽ__/     ヽ   
    /               \  
   /       \     /   |  
   |      ●      ● |  
   |.         (__人__)   | 
   ヽ               / 
   /               \  
  /         ̄ ̄ヽ / ̄  ヽ   
  ヽ_______/ \__/   
[[二二二二二二二二二二二二二二二二
 http://kaomojiya.com/ascii/4page.php[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ruby