sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Module, Class, attr_accessor help?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 290 Views
    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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      I see attr_accessor as being listed under the module class, are there any pitfalls of using it in a class like this:

      module AWESOME_MODULE
        class AWESOME_MODULE;;Cool_class
          attr_accessor(;color)
        end
      end
      
      class_object = AWESOME_MODULE;;Cool_class.new
      class_object.color= "red"
      

      I would like to do that, is it considered standard operating procedure? Or is that bad in any way? I was a little confused by the attr_accessor being a method of the module class, instead of the Class class (or something like that).

      So, any thoughts on this? Good, bad, ugly? Thanks,

      Chris

      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

        Yes it's fine and also standard ops.

        class Class is a subclass of class Module, so inherits the attr_... methods.

        The reason they are defined in class Module is so they can be written as Mixin-Modules, that are mixed into classes using include() and extend().

        I'm not here much anymore.

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

          Awesome, thanks Dan!

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

          1 Reply Last reply Reply Quote 0
          • D Offline
            david.
            last edited by

            I do it that way all the time.

            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