Read in the pickaxe about passing a hash of parameters to a method
(like Rails does a lot)


Aur

On 7/4/07, Ivan Vega <afraid / spam.com> wrote:
> Hi,
>
> I'm trying something very simple, like passing a method a string, and
> two more strings to surround that with... i.e.:
>
> around_string('mystring') {|b, a| b = 'before'; a = 'after';}
>
> The method:
>
> def around_string(string, &block)
>     b, a = yield
>     "#{b}#{string}#{a}"
> end
>
> That of course doesn't work because I still don't get how blocks and
> procs work and what they are. The reason I don't just pass 'a' and 'b'
> as parameters to the method is because the method has other parameters I
> don't want to touch, and it seemed like a block as the last parameter
> would be a good choice (I simplified my example so it's clearer).
>
> So I wanted to know what's the best way to accomplish what I'm trying to
> do...
>
> Thanks for your patience :)
>
> - Ivan V.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>