13 Jan, 2009, Chris Bailey wrote in the 1st comment:
Votes: 0
Ok, so the following function returns an array, which is strange, because it should return an instance of the Item class. Using IRB I was able to make sure that each item in the @eq and @inv ARRAYS are in fact instances of the ITEM class. After calling the get_item method though, it returns an array containing an instance of the object. I can't seem to figure out why, any ideas?


def get_item(loc,name)
if loc == :eq
@eq.each do |item|
if item.name.downcase.include? name.downcase
return item
end
end
elsif loc == :inv
@inv.each do |item|
if item.name.include? name
return item
end
end
end
end
14 Jan, 2009, Stormy wrote in the 2nd comment:
Votes: 0
I'd suggest verifying that an item is being matched, maybe just with a simple #print. If it's not matching an item, then Array#each will return an array.
14 Jan, 2009, Davion wrote in the 3rd comment:
Votes: 0
Does Ruby use any sort of special container class for iterators? I know with STL when iterating a list, you tend to have to dereference the iterator in order to directly access a pointer value. I could be way off though :P.
14 Jan, 2009, Chris Bailey wrote in the 4th comment:
Votes: 0
I'm not at home right now to test that out, but Stormy might well be right. Davion: You don't have to dereference the iterator in Ruby, it pretty much works just how I posted it, IF it's matching the item name. I didn't know Array#each returned an array otherwise, that's good to know. Thanks Stormy.


PS - Story, are you working on any kind of mud project in Ruby?
14 Jan, 2009, Chris Bailey wrote in the 5th comment:
Votes: 0
Oh I see what I did wrong. Line 11 of what I posted was supposed to be "if item.name.downcase.include? name.downcase" Stupid errors. Thanks again Stormy for pointing out that thing about Array#each
14 Jan, 2009, Stormy wrote in the 6th comment:
Votes: 0
Glad I could help. I have an engine in perpetual development, built on top of the TeensyMUD network code.
14 Jan, 2009, Chris Bailey wrote in the 7th comment:
Votes: 0
Hey I love Teensymud! We need a Teensy forum here.
0.0/7