Responses interwoven below.

Quoting Tom Ha <rails-mailing-l...@andreas-s.net>:
> 
> Well, basically *everywhere* where it says "low" in the below code 
> example:
> 
> The "resulting" code...
> ==========================
>   if @user.low == true
>     @low = false
>   elsif @user.low == false
>     @low = true
>   end
> 
>   [...]
> ==========================
>

Breaking your question into pieces.

case @user.low
when true
  @low = false
when false
  @low = true
end

This is exactly equivalent to your code above.  If all you care about is the
falseness (nil or false) or trueness (anything else), it can be simplified to:

@low = !...@user.low
 
> ...is supposed to be "generated" by something like this... (which is NOT 
> yet correct syntax)
> 
> ==========================
>   if @user.{params[:id]} == true
>     @{params[:id]} = false
>   elsif @user.{params[:id]} == false
>     @{params[:id]} = true
>   end
> 

This is harder to handle, your syntax is not valid Ruby, so I have to make
some assumptions what you mean.  Again breaking into pieces:

@user.{params[:id]} isn't valid Ruby.

If @user is a hash, i.e., it was set with something like:

@user = {1 => 2, 3 => 4}

Then @user[params[:id]] is the proper syntax.

The same is true if @user is derived from ActiveRecord.  You will get the
attributes of @user, not the instance variables.  Attributes are stored in the
database, instance variables usually aren't (except of course for the values
in the @attributes hash).

If both @user and the current object instance are ActiveRecords, and both are
only true or false and all values of params[:id] are attribute names:

self[params[:id]] = !...@user[params[:id]]

If all values of params[:id] are methods, i.e. explicit via "def abc()
... end" or implicit (i.e. accessors, e.g. attr_accessor 'abc') then the
previous example becomes:

self.send(params[:id] + '=', !...@user.send(params[:id]])

For most any combination of types, the following is correct:

case @user.send(params[:id])
when true
  self.send(params[:id] + '=', false)
when false
  self.send(params[:id] + '=', true)
end

If "@{params[:id]}" is instance variables without accessors, i.e. private,
someone else will have to answer your question.

HTH,
  Jeffrey




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to