[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

nuB has irb problems

dave

6/14/2006 2:27:00 PM

can't find the correct standalone comparator object for not
equals....in irb
g='give'
g.>('a') >>true
g.<('h') >>true
g.==('give') >>true
.....how does one DO not equals because g.<>('able') >>irb error OR
g.!=('able') >>irb error

.....also do not understand why:
at_hotel=true
if at_hotel puts 'hi' end >>> gives a irb syntax error
....BUT.....
if at_hotel
puts 'hi'
end >>>is oka in irb????

4 Answers

Premshree Pillai

6/14/2006 3:39:00 PM

0

dave wrote:
> g.!=('able') >>irb error

irb(main):004:0> g!="h"
=> true

> ....also do not understand why:
> at_hotel=true
> if at_hotel puts 'hi' end >>> gives a irb syntax error

if at_hotel; puts 'hi'; end

Premshree

Ross Bamford

6/14/2006 3:49:00 PM

0

On Wed, 14 Jun 2006 15:27:05 +0100, dave <BITDOGER@YAHOO.COM> wrote:

> can't find the correct standalone comparator object for not
> equals....in irb
> g=3D'give'
> g.>('a') >>true
> g.<('h') >>true
> g.=3D=3D('give') >>true
> ....how does one DO not equals because g.<>('able') >>irb error OR
> g.!=3D('able') >>irb error
>
> ....also do not understand why:
> at_hotel=3Dtrue
> if at_hotel puts 'hi' end >>> gives a irb syntax error
> ...BUT.....
> if at_hotel
> puts 'hi'
> end >>>is oka in irb????
>

# Don't use dots, especially not for !=3D which isn't even a method

g =3D 'give'
# =3D> "give"

if g !=3D 'able' then "Not equal" end
# =3D> "Not equal"

# Alternatively, if can be used as a statement modifier ...

"Not equal" if g !=3D 'able'
# =3D> "Not equal"

"Not equal" unless g =3D=3D 'able'
# =3D> "Not equal"


-- =

Ross Bamford - rosco@roscopeco.remove.co.uk

dave

6/14/2006 7:41:00 PM

0

I am SUPRISED... that all of the other comparators are messages and CAN
have the dot prefixed to an OBJECT BUT the not equals as in OBJECT.#=
Ross Bamford wrote:
> On Wed, 14 Jun 2006 15:27:05 +0100, dave <BITDOGER@YAHOO.COM> wrote:
>
> > can't find the correct standalone comparator object for not
> > equals....in irb
> > g='give'
> > g.>('a') >>true
> > g.<('h') >>true
> > g.==('give') >>true
> > ....how does one DO not equals because g.<>('able') >>irb error OR
> > g.!=('able') >>irb error
> >
> > ....also do not understand why:
> > at_hotel=true
> > if at_hotel puts 'hi' end >>> gives a irb syntax error
> > ...BUT.....
> > if at_hotel
> > puts 'hi'
> > end >>>is oka in irb????
> >
>
> # Don't use dots, especially not for != which isn't even a method
>
> g = 'give'
> # => "give"
>
> if g != 'able' then "Not equal" end
> # => "Not equal"
>
> # Alternatively, if can be used as a statement modifier ...
>
> "Not equal" if g != 'able'
> # => "Not equal"
>
> "Not equal" unless g == 'able'
> # => "Not equal"
>
>
> --
> Ross Bamford - rosco@roscopeco.remove.co.uk

Martin DeMello

6/14/2006 8:22:00 PM

0

dave <BITDOGER@yahoo.com> wrote:
> I am SUPRISED... that all of the other comparators are messages and CAN
> have the dot prefixed to an OBJECT BUT the not equals as in OBJECT.#=

Note that this keeps == and != consistent - != is simply the boolean
negation of ==. Otherwise you could define them so that they are both
true or false simultaneously.

martin