Page 2 of 5

Re: two things array/ruby related

Posted: Thu Oct 31, 2013 9:47 pm
by Nubeat7
RJHollins wrote:not to distract from the OP ... and thanks for the examples TROG ...

but I've been trying to figure out how to change the output of the RUBY box from the proper ARRAY display:
["1", "a", "X"]


to one that is 'clean' .... 1 a X

or

1
a
X

I'm thinking the array is extracted into a string format. But I more familliar using PRIMS and still easily confused with RUBY. [need more practise :lol: ]

Thanks for info!

use stringarray output for the second example and .join(',') for the first one
you also could add .gsub(/\,/,"") to also remove the commas

Re: two things array/ruby related

Posted: Thu Oct 31, 2013 10:21 pm
by RJHollins
.gsub(/\,/,"")


that's the one I keep forgetting about ... :oops:

I actually need to write this on paper to remember it .... and my name :roll:
:lol:

Re: two things array/ruby related

Posted: Thu Oct 31, 2013 10:59 pm
by Nubeat7
or you put this site in your favourites http://ruby-doc.org/core-2.0.0/String.h ... hod-i-gsub

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 2:11 am
by billv
Thanks for the input Trog...

I got first example ok....but the 'nesting' one is killing me all morning... :?

The nesting example data for 3 arrays is structured like this....
["1/2/3", "a/b/c", "X/Y/Z"]

If i input 1 array it is structured like this
["1","2","3"]...

how can i make this method work using "real" inputs...?

and i can't seem to re-define the split....
should i be re-structuring the arrays(join,insert..ect,ect) till I get
a line of text that looks like ["1/2/3", "a/b/c", "X/Y/Z"]...?

Or is another method???

So it's currently...
my_array = ["1/2/3", "a/b/c", "X/Y/Z"]
I want to basicly...
my_array = [@a1, @a2, @a3]
somehow.. :?..and get result..

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 5:00 am
by billv
I found the issue i had...

If arrays are not the same size exception is raised....

This works fine ifarrays are same size....

Code: Select all

a = [@a]+[@b]
b = a.transpose
column = b[0]
output 0,column

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 11:52 am
by tester
I'm starting to understand less and less from these chats... :D
Module examples are more helpful.

Let me clarify. "Get rows at list of indexes" will look like this I suppose, yes? And rows must not contain commas as a separators in order to work correctly, yes?

BTW, I see that in ruby you can use inputs by @names. What about named outputs?

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 12:10 pm
by tester
trogluddite wrote:You're on the right track - but you need an array where each row is itself an array - i.e. nested array structure. So the string for each row will need converting to array form...

Code: Select all

my_array = ["1/2/3", "a/b/c", "X/Y/Z"]

# Convert rows into sub-arrays
nested_array = my_array.map do |row|
  row.split('/')
end

# You now have a nested array...
# [ ["1","2","3"], ["a","b","c"], ["X","Y","Z"] ]

# Now transpose so that columns become rows and vice versa
transposed_array = nested_array.transpose

# transposed array will now be
# [ ["1","a","X"], ["2","b","Y"], ["3","c","Z"] ]

# Get a column
column = transposed_array[0]  #=> ["1", "a", "X"}


I don't get that one. Could you upload it as a module with text connected on input?

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 12:32 pm
by tester
Okay, I managed that one, I guess.

Two things that are bothering me:
1) ruby window tend to show errors even if there are no errors (some sort of refreshing issue).
2) I see, that I tend to use names that are reserved for something.

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 12:34 pm
by Nubeat7
tester wrote:
BTW, I see that in ruby you can use inputs by @names. What about named outputs?


Code: Select all

output 'myOutputName', value

Re: two things array/ruby related

Posted: Fri Nov 01, 2013 12:40 pm
by tester
One thing regarding "get column" module. How to fill the array with nils, so that it will not produce an error, if some rows have less values?

Like this:

aaa/111/v/5
bbb/222/b/6
ccc/n

Third row is shorter by 2 items, thus it should end like this:

ccc/n//