Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

A question about conditional operators

Status
Not open for further replies.
and

Example:
Code:
test && set
test and set
Syntax:
Code:
expr '&&' expr
expr and expr
First evaluates the left side; if the result is true, evaluates the right side. and does the same as &&, but is a lower priority operator.

or

Example:
Code:
demo || die
demo or die
Syntax:
Code:
expr '||' expr
expr or expr
First evaluates the left side; if the result is false, evaluates the right side. or does the same as ||, but is a lower priority operator.

Ok, so With that said, would the following be true?
and
first evaluates the left side; if the result is false, it does not evaluate the right side.

or
First evaluates the left side; if the result is true, it does not evaluate the right side.

Say, for example, I do not want to overwrite a method that may have already been defined but i want to define it if it hasn't already. I use this code:
Code:
unless Object.const_defined?(:Class) and Class.method_defined?(:method)
  class Class
    def method
      #do this
    end
  end
else
  class Class
    alias old_method method
    def method
      #do this
      old_method
    end
  end
end
I understand that if Class has been defined it will then check if method has been defined within that class, and if not, it will define both, but if method has been defined within Class then it will alias the predefined method.

What I want to know is: if Class has not been defined, will it still try to check if method has been defined? If it did, that would throw an error, wouldn't it?
 

Zeriab

Sponsor

It is simple to test.
Try one where you already have defined the class and and the method
One where you have defined the class but not the method
One where you have not defined the class.

See if it works like you expect it to work in those cases. There in lies the answer ;)

I would guess that what you say holds true btw.
 
Therein lies the problem. I'm on a computer that does not have rmxp and I can not install rmxp on this computer. I very rarely have access to the computer that has rmxp and when I do have access i do not have time to work with rmxp. I am writing most of my scripts using notepad to be tested and debugged later. So i want as little errors as possible so debugging takes less time, thus why I ask questions here that normally require only testing...

EDIT: Nevermind, I forgot about the online interpreter that was linked from the scripting academy. I tested it on there and It worked like a charm. My assumptions were correct.
*Reported for closure*
 
This topic has been resolved. If DraycosGoldaryn or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top