sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    If local_variable == @variable

    Scheduled Pinned Locked Moved Plugins
    8 Posts 3 Posters 272 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      My SU page fonts are huge today,-), my eyes are not that bad, yet. Anyway I notice that I can not test different kinds of variables, as the following fails:

      def anything
        something
        if local_variable == @variable
          something
        else
          something else
        end
      end
      

      While the following works:

      def anything
        something
        if @local_variable == @variable
          something
        else
          something else
        end
      end  
      

      Is it a rule in Ruby that you can not test different kinds of variables? Is there other things I need to be aware of because of this?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        @honoluludesktop said:

        My SU page fonts are huge today,-)

        SCF you mean? At the top of the page, upper right, you can swap between sizes.

        @honoluludesktop said:

        Anyway I notice that I can not test different kinds of variables, as the following fails:

        Fails with error message, or just doesn't do what you want?

        There should be no restrictions, but are you sure you defined all the variables?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          Yeah, at the office, I get to adjust the view zoom font %, so I found that I had to scale down from 125% to 100%. Don't know why the machine woke up at 125%.

          Don't recall error massage, but I didn't separately declare the local variable (vari_1 = 0, vari_2 = 0). OK, I thought that local variables could be created on the fly. Sigh...

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @honoluludesktop said:

            variables could be created on the fly. Sigh...

            ` x=3

            3
            puts 'hello' if y == x
            Error: #<NameError: undefined local variable or method y' for main:Object> (eval):15

            when comparing you need to have initialized the variable.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Note that instance variables doesn't act the same:
              puts 'hello' if @y == x nil

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                OK, thanks.

                1 Reply Last reply Reply Quote 0
                • fredo6F Offline
                  fredo6
                  last edited by

                  @honoluludesktop said:

                  My SU page fonts are huge today,-), my eyes are not that bad, yet. Anyway I notice that I can not test different kinds of variables, as the following fails:

                  def anything
                  >   something
                  >   if local_variable == @variable
                  >     something
                  >   else
                  >     something else
                  >   end
                  > end
                  

                  While the following works:

                  def anything
                  >   something
                  >   if @local_variable == @variable
                  >     something
                  >   else
                  >     something else
                  >   end
                  > end  
                  

                  Is it a rule in Ruby that you can not test different kinds of variables? Is there other things I need to be aware of because of this?

                  you need to initialize the local variables. Otherwise you get an error.

                  Instance variables (with @) are initialized to nil by default, and this is why you don't get an error.

                  Fredo

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    And class variables @@.

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement