Ruby/Rails using || to determine value, using an empty string instead of a nil value

后端 未结 3 581
无人共我
无人共我 2021-02-02 11:46

I usually do

 value = input || \"default\"

so if input = nil

 value = \"default\"

But how can I do this so in

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 12:06

    Maybe irrelavant but I would use highline like this:

    require "highline/import"
    
    input = ask('Input: ') { |q| q.default = "default" }
    

    It works without Rails. Really neat solution.

提交回复
热议问题