0

problem with this code:

parseIcmPage url, '<ul id="topListFilter"', '<div id="footer">'

def parseIcmPage(url, start_point, end_point)
        data = getHtmlPage url
        s = data.index(start_point)
        e = data.index(end_point, s)
        len = e-s
        list_str = data.index[s, len]
        puts list_str, '\n'
end
icm.rb:42: warning: don't put space before argument parentheses
./util.rb:121:in `index': wrong number of arguments (0 for 1) (ArgumentError)
        from ./util.rb:121:in `parseIcmPage'
        from icm.rb:42

not sure why i am getting argumenterror. As can be seen i am passing '<ul id="topListFilter"' as argument 1.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by craiggles
0

You've marked this as solved but I'll post for referential reasoning.

You get a ArgumentError for the method index in your method parseIcmPage, not an ArgumentError for the method parseIcmPage itself.

We then look at how we're calling index and we have three method calls:

s = data.index(start_point)
e = data.index(end_point, s)
list_str = data.index[s, len]

for simplistic reasoning let's say data is the string object, "example", start_pos is the string object, "e" and end_pos is the string object, "a"

data = "example" # obviously in your code it's the markup of the URI
start_pos = "e"
end_pos = "a"

s = data.index(start_pos)
e = data.index(end_pos, s)

len = e - s

# no errors so far and we've called index twice, one index call remaining so
# we know which call causes the error! :)
list_str = data.index[s, len]
# is actually doing
list_str = data.index.[](s, len)
# so it's getting the value of data.index, and then calling the [] method on the result

because we are getting the result of just data.index, you can see we're not passing an argument, thus this is why an ArgumentError is raised.

this was probably just a typo but the correct code would just to be omit the index method call thus leaving,

list_str = data[s, len]

I hope that will help those who may look at this thread in the future.

Edited by craiggles: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.