On Mar 4, 2009, at 5:02 PM, C. Dagnon wrote:

> Ruby has definite positives over Java and even other scripting
> languages, but many negatives too.  One negative is the  
> inconsistency of
> how rules seem to be applied in the language and accompanying  
> toolsets.
> Here are a few that have bitten me:
>
>
> 1. I almost immediately got started with Ruby on Rails and loved the
> idea of partials, but then I found that the ||= idiom doesn't work on
> partials' parameters.
>
> <%  my_param_a ||= 1    # Errors out
>    my_param_a = my_param_a ? my_param_a : 1   # works
> -%>
>
> That seemed odd as I thought both were equivalent, and it broke some  
> of
> the trust I had for Ruby.  Not as much as early Rails' use of 2  
> separate
> variables for RAILS_ENV, but...

What was the exact error? I don't know how ERB in Rails work, but  
sometimes those constructs are method calls and not variables.

> 2. Then when using blocks to process an array I tried to use another
> Ruby control structure:
>
>  arr=[1,2,3,4]
>  arr2 = arr.collect{|ii|  return 0 if ii == 3; ii+1}
>  # result: LocalJumpError: unexpected return
>
> That also caught me off guard - I need the block to return a value, to
> evaluate to a value - but suddenly I'm told that 'return' doesn't mean
> what I think it means?  At least not inside a block (or Proc.new)...

"return" in Ruby has a lexical meaning and can jump to the end of a  
scope (the end of the method). In some contexts, that is not allowed.  
Especially in the case of collect, that has to return an array that is  
as large as the first one.

It is not inconsistent: it is just not Javas return. So the language  
is right to tell you that it is not what you think it means: because  
it ain't.
Don't use it unless you really want to jump.

I for my part find Ruby a rather consistent language. It's just that  
the ruleset is not simple.

Regards,
Florian

--
Florian Gilcher

smtp:   flo / andersground.net
jabber: Skade / jabber.ccc.de
gpg:    533148E2