range object as a parameter

Discussion in 'Ruby' started by Josselin, May 28, 2007.

  1. Josselin

    Josselin Guest

    I trying to use a range object from an array of ranges objects as a parameter


    my_range = [(0..2), (2..5), (5..10), (10..15), (15..25)]

    props = []
    domains = Domain.find:)all)
    # keep track of the number of domains
    @ props[0] = domains.nitems
    k = params[:id] # can be 0, 1 ,2,3,4

    1.step(domains.nitems,1) do |d|
    props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )
    d = d.next
    end

    I got an error : can't convert String into Integer in the line :
    props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )

    is is wrong ?

    thanks for your help

    joss
     
    Josselin, May 28, 2007
    #1
    1. Advertising

  2. Josselin

    Alex Young Guest

    Josselin wrote:
    > I trying to use a range object from an array of ranges objects as a
    > parameter
    >
    >
    > my_range = [(0..2), (2..5), (5..10), (10..15), (15..25)]
    >
    > props = []
    > domains = Domain.find:)all)
    > # keep track of the number of domains
    > @ props[0] = domains.nitems
    > k = params[:id] # can be 0, 1 ,2,3,4
    >
    > 1.step(domains.nitems,1) do |d|
    > props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )
    > d = d.next
    > end
    >
    > I got an error : can't convert String into Integer in the line :
    > props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )
    >
    > is is wrong ?

    Here's a guess: k is a String? Array indices can only be Integers -
    try my_range[k.to_i].

    --
    Alex
     
    Alex Young, May 28, 2007
    #2
    1. Advertising

  3. Josselin

    Josselin Guest

    On 2007-05-28 20:09:43 +0200, Alex Young <> said:

    > Josselin wrote:
    >> I trying to use a range object from an array of ranges objects as a parameter
    >>
    >>
    >> my_range = [(0..2), (2..5), (5..10), (10..15), (15..25)]
    >>
    >> props = []
    >> domains = Domain.find:)all)
    >> # keep track of the number of domains
    >> @ props[0] = domains.nitems
    >> k = params[:id] # can be 0, 1 ,2,3,4
    >>
    >> 1.step(domains.nitems,1) do |d|
    >> props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )
    >> d = d.next
    >> end
    >>
    >> I got an error : can't convert String into Integer in the line :
    >> props[d] = Proposition.find_by_range( ( my_range[k ] ) , ......... )
    >>
    >> is is wrong ?

    > Here's a guess: k is a String? Array indices can only be Integers -
    > try my_range[k.to_i].


    thanks that's it... I was not searching for the right problem... could
    not find the right solution...

    4 years better than 2... don't know why we have been created like that
    ! (or "evolutionned"....... ;-)))
     
    Josselin, May 28, 2007
    #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. Replies:
    46
    Views:
    996
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    424
    James Kanze
    Jul 16, 2008
  3. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    170
    Tomoyuki Kosimizu
    Nov 27, 2003
  4. David Bird
    Replies:
    1
    Views:
    242
    Tiago Macedo
    Jun 23, 2008
  5. Joey Zhou
    Replies:
    5
    Views:
    245
    Joey Zhou
    Apr 15, 2011
Loading...

Share This Page