Question: I have a hash that has a `keys => meaning` relation. Various elements of this hash are:

```
"fish" => "aquatic animal"
"fiend" => "bad person"
"great" => "remarkable"

```

I need to create a function find such that when I use this function `find("fi")`, it should give back both "`fish`" and "`fiend`" along with the definitions. So the output should be:

```
"fish" => "aquatic animal"
"fiend" => "bad person"

```

I am new to regular expressions and to Ruby.

Answer: 
```
  hash.select{ |k,v| k.start_with? pattern }

```
You can do it as a single expression:

```
hash.select { |key, value| key.start_with? prefix }

```

Or if you're using Ruby 1.8:

```
hash.reject { |key, value| not key.start_with? prefix }

```

Examples:

```
{'foo' => 1, 'bar' => 2, 'baz' => 3}.select { |key, value| key.start_with? 'f' } # {'foo' => 1}
{'foo' => 1, 'bar' => 2, 'baz' => 3}.select { |key, value| key.start_with? 'b' } # {'bar' => 2, 'baz' => 3}

```

`select` would keep only pairs that don't match the condition in the block. `str.start_with? prefix` returns true if `str` starts with `prefix` (kind of obvious).

There is a slight awkwardness in the 1.8 code - I'm doing `reject`, instead of `select` and I need to negate the result from `#start_with?`. The reason is that in Ruby 1.8 `Hash#reject` returns a `Hash`, while `Hash#select` returns an array of pairs.