If ....... Then

1 Like

This StackOverflow answer gives a good overview of the Ruby-specific implementation of equality operators.

In the case of ==:

At the Object level, == returns true only if obj and other are the same object. Typically, this method is overridden in descendant classes to provide class-specific meaning.

Translation, please.

Exactly… :slight_smile:

i THINK
a = a == 3 ? 1 : 2

means

if a is equal to 3, then a becomes 1. Otherwise it becomes 2

Xojo has something similar now too, but (if I got it right) I still feel that

if a = 3 then
a=1
else
a = 2
end if

is so much easier to debug.

If you have to stop and wonder what something does, saving a couple of characters of typing was a waste of time.

1 Like

Correct, Xojo does now have what equates to ternary conditions. Essentially the same thing as VBA’s IIF if you have experience there.

Can become

a = If(a = 3, 1, 2)
1 Like

Thank you all for the explanations.

Not if you compare it with Ruby.

Which happens to be exactly what the OP was asking for.

1 Like

Many languages use:

X++ // increment by 1
X-- // decrement by 1

X += 7 // add 7 to X
X -= 5 // subtract 5 from X
X *= 23.5 // multiply x by 23.5 and store in X
X /= 2 // divide X by 2 and store in X

I would love the ++ and – ones to exist.

1 Like

I asked that I don’t know, 10 years ago? I was stoned to death by BASIC purists in the forum that time, because some said they couldn’t understand such grammar. And I said “just don’t use it”. Now that Xojo Web was introduced and JavaScript is kind of blurring things, not sure if such way of thinking persists. But from time to time, not Basic devs brings this question back and it is discarded.

1 Like

But now the languaje is more “ADVANCED”, whe have the VAR…

2 Likes

What is the difference between DIM and VAR ? 3 characters ?

If you want to be able type these shorthand forms, Julian 's ReformatCode script will let you. It will then take that form and reformat it to what Xojo needs it to be.

ReformatCode script