PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > with ? yield :
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
with ? yield :

Réponse
 
LinkBack Outils de la discussion
Vieux 03/12/2007, 18h56   #1
Raimon Fs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with ? yield :

Hello,

I'm new to Ruby and Rails, and I'm learning at the same time I'm reading
books and following some threads on the web, and of course,
experimenting ...

What's the meaning of this: ?
--------------------------------------

session[:auth] ? yield : (
session[:intended_action] = action_name
session[:intended_controller] = controller_name
flash[:notice] = 'You need to be logged in to access this panel'
session_update_time
all_ok = 0
render(:template => 'login/index'))

I understand what it does, but not what means:

? yield : ( ... some code ...)


thanks!

raimon
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 03/12/2007, 19h05   #2
Noah Easterly
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with ? yield :

On Dec 3, 1:56 pm, Raimon Fs <co...@montx.com> wrote:
> Hello,
>
> I'm new to Ruby and Rails, and I'm learning at the same time I'm reading
> books and following some threads on the web, and of course,
> experimenting ...
>
> What's the meaning of this: ?
> --------------------------------------
>
> session[:auth] ? yield : (
> session[:intended_action] = action_name
> session[:intended_controller] = controller_name
> flash[:notice] = 'You need to be logged in to access this panel'
> session_update_time
> all_ok = 0
> render(:template => 'login/index'))
>
> I understand what it does, but not what means:
>
> ? yield : ( ... some code ...)
>
> thanks!
>
> raimon
> --
> Posted viahttp://www.ruby-forum.com/.


so ? : is normally called the trinary operator, and is common to a
bunch of languages (C, Ruby, Javascript, etc ad nauseum).

In ruby,

a?b:c

is shorthand for

if a
b
else
c
end

( not so much in C, since if statements don't have values in C )

So session[:auth] ? yield : ( ... ) either yields to a block passed by
the calling function, or executes the code defined in (...), depending
on whether session[:auth] is truish (not false or nil).
  Réponse avec citation
Vieux 03/12/2007, 19h07   #3
Lee Jarvis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with ? yield :

? is the equivalent to 'if' kinda.. For example

a = 10
if a == 10 then <something> else <something else> end

is the same is

a == 10 ? <something> : <something else>


Hope that ed.

Regards,
Lee
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 03/12/2007, 19h08   #4
Sebastian Hungerecker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with ? yield :

Raimon Fs wrote:
> I understand what it does, but not what means:
>
> ? yield : ( ... some code ...)


foo ? bar : baz
is equivalent to
if foo then bar else baz end

HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

  Réponse avec citation
Vieux 03/12/2007, 19h24   #5
Raimon Fs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with ? yield :

thanks to all !!

now is clear!

Raimon
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09428 seconds with 13 queries