The story
Likely traditional. In this form, perhaps from Abraham Maslow, The Psychology of Science, 1966, page 15 and his earlier book Abraham H. Maslow (1962), Toward a Psychology of Being: : I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail. Similar concept by Abraham Kaplan, The Conduct of Inquiry: Methodology for Behavioral Science, 1964, page 28: : I call it the law of the instrument, and it may be formulated as follows: Give a small boy a hammer, and he will find that everything he encounters needs pounding. Labeled "Baruch's Observation" (after Bernard Baruch) in The Complete Murphy's Law: A Definitive Collection (1991) by Arthur Bloch. Also often attributed, without citation, to Mark Twain (for example in Jonathan Haidt, The Righteous Mind, page 9).
Etymology from Wiktionary, CC BY-SA 4.0.