Forum: Ruby Help with iterating nested arrays

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F881b7a48bcf6f1982af055755ead15a?d=identicon&s=25 Mitko Kostov (mitkok)
on 2008-11-03 15:57
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.
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2008-11-03 16:15
(Received via mailing list)
On Mon, Nov 3, 2008 at 3:56 PM, Mitko Kostov <mitko.kostov@gmail.com>
wrote:
>  end
> 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.
F881b7a48bcf6f1982af055755ead15a?d=identicon&s=25 Mitko Kostov (mitkok)
on 2008-11-03 17:11
Jesús Gabriel y Galán wrote:
> 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.
This topic is locked and can not be replied to.