Help with deleting bitmaps

i'm trying to write a script and i created a method:
Code:
def Cache.generate_bitmap(filename)
      base_bitmap = Cache.battler(filename, 0)
end
What if i want to delete that bitmap from Cache?
Sorry i'm a noob
You can use Cache.clear, but that clears your whole cache.
Probably something like this
Ruby:
module Cache
  # filepath example: 'Graphics/Battlers/Angel'
  def self.dispose(filepath, hue = 0)
    key = [filepath]
    key << hue if hue != 0
    return unless @cache[key]
    
    @cache[key].dispose
    @cache[key] = nil
  end
end

I've moved this thread to Learning Ruby and RGSSx. Thank you.

KK was close to the solution but it can be reduced to its minimum expression.

Code:
module Cache
# filepath example: 'Graphics/Battlers/Angel'
def self.dispose(filepath, hue = 0)
key = [filepath]
key << hue if hue != 0
@cache[key].dispose
@cache.delete(key)
end
end

It's weird how this board doesn't let me include spaces as indentation markers...
@kyonides If the entry doesn't exist in the cache, you're going to get an "undefined method `dispose` for nil class" error.
Next suggestion...
Code:
module Cache
# filepath example: 'Graphics/Battlers/Angel'
  def self.dispose(filepath, hue = 0)
    key = hue > 0 ? [filepath, hue] : [filepath]
    @cache[key].dispose rescue nil
    @cache.delete(key)
  end
end
Technically works, but it's bad to use inline rescues. Make it a force of habit to avoid doing that.
I really don't understand why you're trying to "one-up" me by using less lines of code when the solution I posted was enough to close this thread.
If we go by even lesser lines, we can go by this as well
Code:
module Cache
  def self.dispose(filepath, hue = 0)
    key = hue > 0 ? [filepath, hue] : [filepath]
    @cache.delete(key).dispose rescue
  end
end
But KK's original solution is already work without issue.
Thanks a lot to everyone, problem solved!!!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-deleting-bitmaps.117165/