[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Help with iterating nested arrays

Mitko Kostov

11/3/2008 2:56:00 PM

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.
--
Posted via http://www.ruby-....

2 Answers

Jesús Gabriel y Galán

11/3/2008 3:14:00 PM

0

On Mon, Nov 3, 2008 at 3:56 PM, Mitko Kostov <mitko.kostov@gmail.com> wrote:
> 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.

Mitko Kostov

11/3/2008 4:10:00 PM

0

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.
--
Posted via http://www.ruby-....