English 中文(简体)
在使用废墟时及时填满现有答案
原标题:Prefill prompt with existing answer when using ruby s Highline#ask
  • 时间:2011-10-26 14:10:34
  •  标签:
  • ruby

I m getting input from a user using Ruby s Highline gem. I m asking the following

note = ask("Enter a note for this entry: ")

This is fine, but If the user edits the entry I want to populate the prompt with their existing answer for this question so that it can be edited directly instead of entering it again.

类似:

note = ask("Enter a note for this entry: ", :current => note)

# Output:    
Enter a note for this entry: the current note_
问题回答

A little bit too late, but:

The best solution i found for this problem was to use the completion attribute in the ask block.
So when you write the following code:

input = "Foobar" #default
loop do
    input = ask("Input: ") { |q| q.completion = [input]; q.readline = true }
end

你们最后要这样做。

Input: Fo<hit tab>
Input: Foobar 

每次更新<代码>completion 因此,你可以很容易地从您的最后一行获得投入。

我从未使用过高线,但申请方法的文件表明,它是一种选择性的屏障。 我认为,这是你如何做的:

note = ask("Enter a note for this entry: ") { |q| q.default = "Default Answer" }




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签