On 8/16/07, Simon Schuster <significants / gmail.com> wrote:
> whoa, can you explain a little what's going on here? I tried it and
> changed it around in irb but I can't really figure out what's going
> on.
>

#{} just happens to work more places than string literals:

If it helps clear it up, /#{needle}/ is roughly equivalent to

Regexp.new("#{needle}") which is sort of a silly use of interpolation,
so let's write it as:
Regexp.new(needle)

So yeah, the string "bar" was used to construct the regexp /bar/.

> >
> > For added fun, try string interpolation inside regular expressions!
> >
> > haystack = "foobarbaz"
> > needle = "bar"
> >
> > haystack =~ /#{needle}/
> > => 3
> >
> > yeah :D
> >
> >
>
>