Re: [wtr-general] Use ruby script to get logs from linux server.

2010-09-30 Thread Željko Filipin
On Thu, Sep 30, 2010 at 5:39 AM, Wesley Chen cjq@gmail.com wrote: I tried your suggestion, but I didn't find the solution. You still did not say what is the problem! :) What did you try? Show us the code. (Remove username/password.) Željko -- Before posting, please read

[wtr-general] Random value from a select list

2010-09-30 Thread ISmellGas
Hi, I am trying to populate a select list with a random value from the list but I am not sure how I can achieve this. Is it possible to get the contents of the select list into an array, count how many items are in that array and select a random one? Sorry if this is a slightly incoherent

Re: [wtr-general] Random value from a select list

2010-09-30 Thread Željko Filipin
On Thu, Sep 30, 2010 at 3:15 PM, ISmellGas guard1883-goo...@yahoo.co.uk wrote: Is it possible to get the contents of the select list into an array, count how many items are in that array and select a random one? Sure, select_list.options will return array of contents, then just pick a random

Re: [wtr-general] Random value from a select list

2010-09-30 Thread Felipe Knorr Kuhn
Another option: array[rand(array.size)] On Thu, Sep 30, 2010 at 10:25 AM, Željko Filipin zeljko.fili...@wa-research.ch wrote: On Thu, Sep 30, 2010 at 3:15 PM, ISmellGas guard1883-goo...@yahoo.co.uk wrote: Is it possible to get the contents of the select list into an array, count how many

[wtr-general] Re: Random value from a select list

2010-09-30 Thread ISmellGas
Ok, I have given it a go and it seems to work. This is pretty basic so any tips will be gratefully received! @contents = b.select_list(:name, mydropdown).getAllContents @length = b.select_list(:name, mydropdown).getAllContents.length @random = Kernel.rand(@length) @value = @conten...@random]

Re: [wtr-general] Re: Random value from a select list

2010-09-30 Thread Željko Filipin
On Thu, Sep 30, 2010 at 4:29 PM, ISmellGas guard1883-goo...@yahoo.co.uk wrote: @contents = b.select_list(:name, mydropdown).getAllContents @length = b.select_list(:name, mydropdown).getAllContents.length You could do it this way: @length = @contents.length @random = Kernel.rand(@length)

[wtr-general] Re: Random value from a select list

2010-09-30 Thread ISmellGas
@length = @contents.length Ahhh...yes, thats a bit neater. Why is everything in instance variables (they begin with @)? I am not sure really. I find it easier to pick out variables when they start with @. Is there a disadvantage doing it this way or is it just not the done thing? -- Before