On Mar 12, 4:07 pm, ara.t.how... / noaa.gov wrote:
> On Mon, 12 Mar 2007, Michael Strelnikov wrote:
> >> I would be interested in hearing what you want to do with text substitution
> >> that you cannot already do with standard Ruby metaprogramming techniques.
>
> > Easy.
> > Let's we have following function:
> > * set_default(var, val)
> > -- if variable "var" is not defined (not existed) then assign value "val"
> > else do nothing.
>
> > The variable could be ANY type including "Fixnum".
>
> > Try to implement it using standard techniques.
>
>      harp:~ > cat a.rb
>      unless defined? var
>        var = 42
>      end
>
>      p var
>
>      harp:~ > ruby a.rb
>      42
>
> -a
> --
> be kind whenever possible... it is always possible.
> - the dalai lama

I know it but imagine you must do it 100 times?
I'd rather write:
set_default(var1, 15)
set_default(myvar1, "string")
...
set_default(lastvar, myhash)

In your case I must use "var" twice. Don't you think it is too much?