Help with iterating nested arrays

M

Mitko Kostov

Hello, guys. I'm learning now Ruby and Shoes.
I'm using this code to get username and it's status from twitter:

@name = []
@status = []

def timeline
Twitter::Base.new('username','password').timeline.each do |s|
@name << s.user.name
@status << s.text
end
[@name, @status]
end

t = timeline

And then t is [["John", "Daniel", "Marry"],["Having
launch","Sleeping","Bored"]]
And in Shoes I have to use para to print the name and the status, but
don't know how.

Suggestions ?

Mitko Kostov.
 
J

Jesús Gabriel y Galán

Hello, guys. I'm learning now Ruby and Shoes.
I'm using this code to get username and it's status from twitter:

@name = []
@status = []

def timeline
Twitter::Base.new('username','password').timeline.each do |s|
@name << s.user.name
@status << s.text
end
[@name, @status]
end

t = timeline

And then t is [["John", "Daniel", "Marry"],["Having
launch","Sleeping","Bored"]]
And in Shoes I have to use para to print the name and the status, but
don't know how.

Suggestions ?

irb(main):008:0> arr = [["John", "Daniel", "Marry"],["Having
launch","Sleeping","Bored"]]
=> [["John", "Daniel", "Marry"], ["Having launch", "Sleeping", "Bored"]]
irb(main):009:0> arr[0].zip(arr[1]).each {|name,action| p "#{name} is
#{action}"}
"John is Having launch"
"Daniel is Sleeping"
"Marry is Bored"

I think in Shoes you can do this loop creating paras using both elements.

Jesus.
 
M

Mitko Kostov

Jesús Gabriel y Galán said:
irb(main):008:0> arr = [["John", "Daniel", "Marry"],["Having
launch","Sleeping","Bored"]]
=> [["John", "Daniel", "Marry"], ["Having launch", "Sleeping", "Bored"]]
irb(main):009:0> arr[0].zip(arr[1]).each {|name,action| p "#{name} is
#{action}"}
"John is Having launch"
"Daniel is Sleeping"
"Marry is Bored"

I think in Shoes you can do this loop creating paras using both
elements.

Jesus.
Thanks, dude.
It works great.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top