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

    Question about "puts" "Kernel.puts" "Kernel::puts"

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 677 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.
    • W Offline
      wikii
      last edited by Gábor

      where are the differences bewteen puts , Kernel.puts ,Kernel::puts?

      1 Reply Last reply Reply Quote 0
      • W Offline
        wikii
        last edited by

        Thank you.
        regard.

        1 Reply Last reply Reply Quote 0
        • tt_suT Offline
          tt_su
          last edited by

          Nothing - just one of Ruby's multiple ways of doing things.
          All Kernel methods are available available in the global scope - that is - they are available everywhere.

          puts == Kernel.puts == Kernel::puts

          To be more specific, All objects inherit Kernel - because all objects inherit Object.

          ` Object.ancestors

          => [Object, Kernel]`

          The . vs :: is just a syntax difference that has no affect on the behaviour.

          In practise people use . for method calls, and :: for constants.

          MyModule::MyClass.mymethod
          MyModule::MyClass::MyConstant

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

            Functionally, there is no difference.

            BUT.. technically, Kernel::puts(), is a COPY of the instance edition of puts() that got mixed into Object, and will get inherited by ALL other classes and modules.

            The Ruby Core Team wrote the Kernel module as both a Mixin and a Library module. They used the module_function() method, so that all the library instance methods (that get mixin in using include,) had module method copies made. These copies can only be called by qualifying them with the Kernel module name.

            [ruby:1c8jtequ]Kernel.module_eval "class<<self; method(:puts).inspect; end;"
            >> #<Method: Class(Kernel)#puts>
            Kernel.module_eval "method(:puts).inspect;" %(#000000)[>> #<Method: Kernel.puts>]

            🤓

            I'm not here much anymore.

            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