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

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值