Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: quick newbie true/false/nil question
Drew Olson
2/13/2007 8:39:00 PM
Jason Mayer wrote:
> I ran across this line of code today, and it doesn't make sense to me.
>
> if ((klass = CommDispatcher.check_hash(path)) == nil)
I don't know anything about CommDispatcher, but I'd assume you could
rewrite the above code like so:
if (!CommDispatcher.check_hash(path))
The code above seems like a pretty bad code example.
-Drew
--
Posted via
http://www.ruby-...
.
1 Answer
Dejan Dimic
2/13/2007 9:18:00 PM
0
On Feb 13, 9:39 pm, Drew Olson <olso...@gmail.com> wrote:
> Jason Mayer wrote:
> > I ran across this line of code today, and it doesn't make sense to me.
>
> > if ((klass = CommDispatcher.check_hash(path)) == nil)
>
> I don't know anything about CommDispatcher, but I'd assume you could
> rewrite the above code like so:
>
> if (!CommDispatcher.check_hash(path))
>
> The code above seems like a pretty bad code example.
>
> -Drew
>
> --
> Posted via
http://www.ruby-...
.
The above code is certainly not a nice-looking one but that was not
the question.
I suppose that the puzzling part was that the variable klass will be
assigned with return value from CommDispatcher.check_hash(path) and
that that value could be nil.
It is true, if we presume that it is a possible return value from
CommDispatcher.check_hash method.
The assignment inside the if condition is not a good but it is a
common construction especially if you come form C++ world.
Ruby has far more interesting constructions but it all depends on a
context and mostly on programming style.
Generally this assignment inside the if condition should be avoided.
Dima
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: quick newbie true/false/nil question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password