two things array/ruby related

For general discussion related FlowStone
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: two things array/ruby related

Post 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
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: two things array/ruby related

Post 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:
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: two things array/ruby related

Post by Nubeat7 »

or you put this site in your favourites http://ruby-doc.org/core-2.0.0/String.h ... hod-i-gsub
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: two things array/ruby related

Post 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..
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: two things array/ruby related

Post 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
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Post 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?
Attachments
get-rows.fsm
(453 Bytes) Downloaded 932 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Post 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?
Attachments
get-columns.fsm
(674 Bytes) Downloaded 959 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Post 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.
Attachments
get-columns.fsm
(520 Bytes) Downloaded 976 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: two things array/ruby related

Post 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
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: two things array/ruby related

Post 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//
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Post Reply