I would write the whole thing as:

```rb
result = ""
if query
  tap_dir.find_formula do |child|
    basename = child.basename(".rb").to_s
    result = basename if basename == query
  end
end
```