On 03.10.2008 08:22, list. rb wrote:
> Awesome!
> For the record, this is the code mentioned in the blog:
> 
>    1  if (comments = @attributes['comments']) &&
> comments.is_a?(String)   2    @attributes['comments'] =
> comments.split(" ")   3  end

Good point.  Sorry for not including this.

> I never knew it was possible to define a variable from within a condition.

Actually the picture may become simpler if you remember that there is no 
distinction between statement and expression in Ruby.  Every line of 
code is an expression and thusly has a value.  So "if a = 123" is not so 
much different from "a = 123" - only in the latter case the result of 
evaluating the expression is not used.

> Goes to show you that ruby offers plenty of rope to hang yourself if you are
> not careful. Correction -I have accidentally done it in the past and never
> viewed it as a feature until now.

:-)  There's a lot of rope in other programming languages as well - it's 
just of a different material. :-)

> One thing I found intriguing, was how the conditions were looking at the
> response from the definition, not the value of the variable being defined.

In the case of an assignment there is no difference between the two. 
The result of evaluating an assignment is the new value of the variable.

One additional hint: assignment operators are evaluated right to left as 
opposed to other operators.

> That makes sense in thinking about it but
> 
> For example, in IRB the second line yields false:
>      irb(main):001:0> (a = nil)
>      => nil
>      irb(main):002:0> (!a = a)
>      => true

This is actually the same as "!(a = a)".

> However neither of these two yield true in a conditional:
>      puts "you wont see this" unless (a = nil) or (!a = a)

This is not correct: _because_ the second expression yields "true" you 
won't see the output (you used "unless"):

irb(main):003:0> puts "you wont see this" unless (a = nil) or (!a = a)
=> nil
irb(main):004:0> puts "you wont see this" if (a = nil) or (!a = a)
you wont see this
=> nil
irb(main):005:0> (a = nil) or (!a = a)
=> true
irb(main):006:0>

Cheers

	robert


PS: please try to avoid top posting.