Whether a player is in an offside position or not is determined when the ball is last played by a teammate. This is described (albeit in a poorly worded manner) on p. 36 of the 2015/16 FIFA Laws of the Game (emphasis on relevant phrases mine):
A player in an offside position is only penalised if, at the moment the ball touches or is played by one of his team, he is, in the opinion of the referee, involved in active play by:
- interfering with play or
- interfering with an opponent or
- gaining an advantage by being in that position
On p. 110, in the interpretations section, it is elaborated on what these three somewhat ambiguous sub-clauses mean (emphasis once again mine):
- “interfering with play” means playing or touching the ball passed or
touched by a team-mate
- “interfering with an opponent” means preventing an opponent from playing or being able to play the ball by clearly obstructing the opponent’s line of vision or challenging an opponent for the ball
- “gaining an advantage by being in that position” means playing a ball
- that rebounds or is deflected to him off the goalpost, crossbar or an opponent having been in an offside position
- that rebounds, is deflected or is played to him from a deliberate save by an opponent having been in an offside position
A player in an offside position receiving the ball from an opponent, who
deliberately plays the ball (except from a deliberate save), is not considered to have gained an advantage.
Judging from your question, it seems that the attacker that the ball ricocheted towards was in an offside position when the shot was taken. If they weren't, there can be no offence.
Putting this together, further elaboration is needed upon what is meant by blocked by a defender in your original question.
If the ball merely deflected off the defender (as is implied by your question and the use of the word ricocheted), an offside offence has been committed. The attacker is penalised for gaining an advantage by being in that position by playing a deflection off an opponent.
If the defender deliberately tried to play the ball, it needs to be determined whether it was a deliberate save or not. If the ball was heading towards the goal (since it was a shot), it probably was a deliberate save, and there would still be an offside offence. However, if this was a cross or pass not heading towards the goal and the defender deliberately played the ball, there would be no offside offence committed here.
It is irrelevant here if the ball does not go where the defender intended - all that matters when determining whether the defender's contact with the ball is a deflection or deliberately played is whether they attempted to play it or not.
In your example, it appears the offence was called before the attacking player touched the ball. Usually, the player is required to play the ball before an offside offence is called by the refereeing team. However on p. 113 it says:
A player in an offside position may be penalised before playing or
touching the ball, if, in the opinion of the referee, no other team-mate in an onside position has the opportunity to play the ball.
This is done to avoid unnecessary collisions between attackers and defenders (particularly the goalkeeper), and large delays in having to bring the ball back to where the attacker was positioned when the ball was played for the free kick when it's completely obvious an offside offence is about to occur.