ID but =/= Quantity

Hello, me again with another script issue.

I was breaking my head for 2 days in a row with this. In a script I'm trying to edit, I can't figure out how to create the next script call.

This is the original script call that work perfectly:

def has_card_in_deck?(id)
actor = $game_actors[$game_variables[27]]
for card in actor.deck
return true if card.id == id
end
return false
end

This return me if the card with a certain ID is in the deck of my actor.

Now, the problem is that I tried to make another similar script call and I though it would be easy, but is not...

def has_2_cards?(id)
actor = $game_actors[$game_variables[27]]
for card in actor.deck
return true if card.id == id * 2
end
return false
end

(This is just an example)

I want to create the almost exact script call but instead to return me if there's any copy of the card with that ID, I need to return me if there's 2 or more with the same id. I read a lot of articles of ruby code, but can't figure out how to separate the "ID" and the "object quantity". I can't find a way to ask by code how many copies of something with the same ID I have in the deck. I'm really struggling with this one. Thanks in advance to whoever hero who can help me out with this!
So what you've done with that code is checked whether any card in the player's deck has an ID that's double that of the one you're checking for, which is obviously not what you intended.

If you want to check whether there are two or more that match, this should do the trick:

Ruby:
def has_2_cards?(id)
  actor = $game_actors[$game_variables[27]]
  return actor.deck.count { |card| card.id == id } >= 2
end

But better yet, you can future-proof this and make it more versatile:

Ruby:
def has_x_cards?(id, count)
  actor = $game_actors[$game_variables[27]]
  return actor.deck.count { |card| card.id == id } >= count
end
OMG that was fast!
Thanks man, it work! You're a hero!
OMG that was fast!
Thanks man, it work! You're a hero!
Your original can be streamlined in a similar way:

Ruby:
def has_card_in_deck?(id)
  actor = $game_actors[$game_variables[27]]
  return actor.deck.any? { |card| card.id == id }
end

Original thread: https://forums.rpgmakerweb.com/threads/id-but-quantity.146833/