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

    Menu, require and .rb files

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 309 Views 4 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.
    • B Offline
      bizello
      last edited by

      Hi guys,

      I've read some posts about require and rb files.
      So, I would like to know if is possible you have a menu that each sub item call a script or function inside differents .rb files? How to do this?
      I have a main scritp and inside it there are a lot of function that can become smaller functions in separate files used by mora than one script.
      Example: I have two rb files: file1.rb and file2.rb.
      File1.rb do an action that use a function from file2.rb . But file2.rb can work alone too. So, I want to create a menu with two subitem to choose file1.rb or file2.rb.
      This would be amazing! I could separate my functions and use them in several othes scripts, without copy the code lines.
      Thanks

      Sérgio A.Bizello

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        If you set up each script as a module or a class you can call different aspects of the various methods it contains...
        You can pass arguments like MYtool.new(1) or Mytool.new(2) and in the class's def initialize(opt=1) method of Mytool class you have a 'case' test 'opt 1' do this method and 'opt 2' do this other method etc...
        With a module you'll end up with something like the Geom module and you would use it like that - Geom.Point2d.new(...) or Geom.Transformation.scaling(...) etc etc...

        TIG

        1 Reply Last reply Reply Quote 0
        • C Offline
          Cleverbeans
          last edited by

          Thankfully Ruby makes this simple, just wrap it all up in a module and you can split it over multiple files. For example...

          File 1

          
          module MyModule
              def foo(x)
                  puts(x)
              end
          end
          
          

          File 2

          
          module MyModule
              def bar()
                   foo("Hello World!")
              end
          end
          
          

          and by Ruby magik the call to bar works since it's in the same namespace.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            We have topic for discussing Ruby Modules:
            [talk] Using Ruby Modules

            and an informational topic:
            [info] Using Ruby Modules

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • B Offline
              bizello
              last edited by

              Thanks guys,
              I'll try Ruby modules
              SérgioBizello

              Sérgio A.Bizello

              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