2011-09-02 40 views
2

我有這個作爲我的代碼如何在Ruby Shoes中顯示數組的輸出?

openAll = File.open('N:\Josh\Blondie\db.txt') 
allNumbers = Array.new 
allNumbers=[] 
    openAll.each_line {|line| 
    allNumbers.push line 
    } 

    puts allNumbers 

,我希望能夠與紅寶石鞋新窗口中顯示此代碼的輸出,我似乎無法得到它的顯示儘管如此。該文件的內容是名稱和電話號碼。

任何想法?

+0

也許你應該在這裏說一些代碼,告訴我們你已經嘗試了什麼,除了代碼顯示我們你有一個數組中的數據。 – Ryanmt

回答

2

這裏的輸出文本到鞋子窗口的一個例子。使用puts語句只輸出到shell,而不輸出到Shoes應用程序。

Shoes.app :title => "GUI RAW file converter, for the CLI challenged", 
    :resizable => true do 
    background white 
    stack do 
    flow { 
     background gray, :height => 30 
     caption "Caption", :margin => 8, :stroke => white 
     stack { 
     para 'This is a fancy line I just printed to the window' 
####### Here's an example line you could use to put out the array... 
     allNumbers.each do |number| 
      para "#{number}" 
     end 
     } 
    } 
    end 
end 
0

我想你應該使用方法Kernel#alert而不是Kernel#puts。

http://shoesrb.com/manual/Built-in.html

+0

雖然'alert'會讓鞋子實際上做些事情,但與OP的'puts'語句相比,警報將導致警報或彈出警告框,而不是鞋子窗口中的內容。 – Ryanmt