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.

[Resolved] @variable.object?

Hi and thanks in advance.
I need a way to know what is contained in a variable. Lets say for example:

@a = 1

Is there a way to determine that @a is a NUMBER

or

@a = 'name'

Is there a way to determine that @a is a STRING

etc

Thanks
 

EOG

Member

There are few ways.

1.
is_a?(mod) or kind_of?(mod)
Code:
 

a = 1

 

if a.is_a?(Numeric)

end

 

if a.is_a?(String)

end

 

a = Scene_Map.new

 

if a.is_?(Scene_Map)

end

 

2.
class
Code:
 

a = 1

if a.class == Fixnum

end

 

In my oppinion is_a?(mod) is the best.
 

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