nuB has irb problems

D

dave

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????
 
R

Ross Bamford

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"
 
D

dave

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.#=
 
M

Martin DeMello

dave said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top