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

[Ruby笔记]7.ruby -e ' " 单引号、双引号对比

2016-05-20 03:16 501 查看

environment

Windows

PowerShell

ruby -e

使用
ruby -e "..."
可以在命令行直接运行脚本

PS C:\Users\Administrator\RubyCode> ruby -e "print 'Enter a name: '; print gets.reverse"
Enter a name: Tom

moT


’ vs “

自己机器,在
powershell
里结合
-e
选项,使用单引号遭遇错误:

PS C:\Users\Administrator> ruby -e 'puts "hell world"'
-e:1:in `<main>': undefined local variable or method `hell' for main:Object (NameError)


-e
后面使用双引号
框起来就没有问题了:

PS C:\Users\Administrator> ruby -e "puts 'hell world' "
hell world


单双引号的具体区别如下:

C:\Users\Administrator\RubyCode> irb

irb(main):001:0> puts "Hi #{1+1}"
Hi 2
=> nil

irb(main):002:0> puts 'Hi #{1+1}'
Hi #{1+1}
=> nil
irb(main):003:0>


reference

《The Well-Grounded Rubyist, Second Edition》

(https://www.manning.com/books/the-well-grounded-rubyist-second-edition)

1.4.1. Interpreter command-line switches

Difference betweem double quotation marks ” and single quotation mark ’ in Ruby [duplicate]

http://stackoverflow.com/questions/25557052/difference-betweem-double-quotation-marks-and-single-quotation-mark-in-ruby

  -= ∧_∧ エ
-=≡(;´(エ)`)ラ
  -= (つ┳つ イ
-=≡ / ┃/ コ
-=≡ / / ┃) ッ
 ◎━\)┻◎ チ
 ̄ミ ̄ ̄ ̄キ ̄ ャ
 http://emoji.vis.ne.jp/kickboard.htm[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ruby powershell windows