class Foo
def initialize(name)
@name = name
end
end
arr = Array.new
a = Foo.new 'wrong'
b = Foo.new 'right'
arr.push a,b
arr.detect {|item| item.name.include? 'rig'}
Rehearsal ————————————————-
100 each: 0.000000 0.000000 0.000000 ( 0.000730)
1000 each: 0.010000 0.000000 0.010000 ( 0.007348)
10000 each: 0.060000 0.010000 0.070000 ( 0.072144)
100 detect: 0.000000 0.000000 0.000000 ( 0.001251)
1000 detect: 0.010000 0.010000 0.020000 ( 0.012152)
10000 detect: 0.100000 0.020000 0.120000 ( 0.120309)
—————————————- total: 0.220000sec
user system total real
100 each: 0.000000 0.000000 0.000000 ( 0.000696)
1000 each: 0.010000 0.000000 0.010000 ( 0.006433)
10000 each: 0.050000 0.020000 0.070000 ( 0.071875)
100 detect: 0.000000 0.000000 0.000000 ( 0.001138)
1000 detect: 0.010000 0.000000 0.010000 ( 0.011963)
10000 detect: 0.110000 0.020000 0.130000 ( 0.122819)
Here is our basic item class, it's very simple right now but it keeps track of whether or not an item is equipped.
And here is the item equipping command.
The characters inventory is nothing more than an Array containing instances of Item objects. I can't think of a better way of figuring out if an item is in their inventory! :P