Help with iterating nested arrays

Discussion in 'Ruby' started by Mitko Kostov, Nov 3, 2008.

  1. Mitko Kostov

    Mitko Kostov Guest

    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-forum.com/.
     
    Mitko Kostov, Nov 3, 2008
    #1
    1. Advertising

  2. On Mon, Nov 3, 2008 at 3:56 PM, Mitko Kostov <> 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.
     
    Jesús Gabriel y Galán, Nov 3, 2008
    #2
    1. Advertising

  3. Mitko Kostov

    Mitko Kostov Guest

    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-forum.com/.
     
    Mitko Kostov, Nov 3, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CamelR

    Iterating through a nested list

    CamelR, Apr 16, 2006, in forum: Python
    Replies:
    2
    Views:
    370
    Marc 'BlackJack' Rintsch
    Apr 16, 2006
  2. Philipp
    Replies:
    21
    Views:
    1,160
    Philipp
    Jan 20, 2009
  3. carl
    Replies:
    5
    Views:
    2,431
    James Kanze
    Nov 25, 2009
  4. Arti Singh
    Replies:
    0
    Views:
    122
    Arti Singh
    Feb 25, 2010
  5. Robert Mark Bram

    Iterating through nested associative arrays

    Robert Mark Bram, May 23, 2008, in forum: Javascript
    Replies:
    4
    Views:
    163
    Robert Mark Bram
    May 24, 2008
Loading...

Share This Page