sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Puts current module & method in ruby console

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 388 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.
    • M Offline
      Matt666
      last edited by

      Hi all.

      Sorry if you don't understand at all.... 😳

      Since a long time I want to show complete method names when user starts one of my plugins.
      I think I've found a solution, but not with native methods.

      Here is the method:

      <span class="syntaxdefault">def get_current_method<br />  return </span><span class="syntaxkeyword">$</span><span class="syntaxdefault">1 if  </span><span class="syntaxkeyword">/`</span><span class="syntaxdefault">(.*)'/.match(caller.first)<br />end</span>
      

      And code I put in all my plugins:

      <span class="syntaxdefault"></span><span class="syntaxkeyword">(</span><span class="syntaxdefault">self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_s </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'main'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> puts</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"#{self}.#{get_current_method}"</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> puts</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">get_current_method</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
      

      Do you have a solution to do the same with some native methods? Or perhaps you use another bit of code?
      Thank you!
      😉

      Frenglish at its best !
      My scripts

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

        Is this for debugging only?

        It is rather tedious to have to insert a debug line into each method.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • M Offline
          Matt666
          last edited by

          Hi Dan.
          No debugging, just the command of the running plugin. If you want to know command of a plugin, just open the ruby console and run the plugin by the menu or toolbar... An information.

          Frenglish at its best !
          My scripts

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            I'm not sure if I understand the question entirely, but it sounds like you just want to show the method that is called every time the user runs the plugin? Why don't you just puts it to the console? Lots of ways to do that. One could be to add it to the menu command. If you have something like this:

            menu.add_item("My Plugin") { My_module::My_class.my_method }

            Well, those braces can be expanded to as many lines of code as you would like. You could write it like this:

            menu.add_item("My Plugin") do puts "My_module::My_class.my_method" My_module::My_class.my_method end

            Then every time they run the plugin, it will echo the method to the console.

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

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

              @matt666 said:

              No debugging, just the command of the running plugin.

              Then why are you asking for a way native Ruby methods ?

              @matt666 said:

              If you want to know command of a plugin, just open the ruby console and run the plugin by the menu or toolbar... An information.

              Why not just open the rb in an editor, and find the command in the file ?

              BTW.. sometimes there is good reason for a command to be kept private, a commercial plugin, or a Pro only plugin.
              The writer of a plugin, has the right, to not allow their plugin (or it's tools,) to be called in ways that could defeat the license, or cause other problems.

              If the writer wants to publish the commands, they would do so in a README document that comes with the plugin.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by

                Hi Dan and Chris. Thank you for your answers !

                @chris said:

                Well, those braces can be expanded to as many lines of code as you would like. You could write it like this:
                Yes, but I wanted to have a automated method... no need to write Module::Sub_module.method, just copy a line that returns current method in the ruby console.

                @dan said:

                Why not just open the rb in an editor, and find the command in the file ?
                that's what I do when I search the command. But I am not sure a "non-ruby" user could find this command easily.

                @unknownuser said:

                BTW.. sometimes there is good reason for a command to be kept private, a commercial plugin, or a Pro only plugin.
                The writer of a plugin, has the right, to not allow their plugin (or it's tools,) to be called in ways that could defeat the license, or cause other problems.
                I am not saying this bit of code MUST be inserting in each plugin, of course... 😉 Just for MY personal plugins, because I like transparency.. 😄 I just asked this forum if someone had a better (or a native) way to do like my little method...

                Frenglish at its best !
                My scripts

                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