SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: private?

Threaded View

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,658
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    private?

    I'm trying to understand a ruby class,\
    Code Ruby:
    class Timer
     
      attr_accessor :seconds
     
      def initialize
        @seconds = 0
      end
     
      def time_string
        convert(@seconds)
        "#{padded(@hrs)}:#{padded(@min)}:#{padded(@sec)}"
      end
     
      private
     
      def padded(num)
        if num <= 9
          "0#{num}"
        else
          "#{num}"
        end
      end
     
      def convert(num)
        if num >= 3600
          @hrs = num / 3600
          @min = (num - (@hrs * 3600)) / 60
          @sec = num - (3600 + (@min * 60))
        elsif num < 3600 && num >= 60
          @hrs = 0
          @min = num / 60
          @sec = num - (@min * 60)
        else
          @hrs = 0
          @min = 0
          @sec = num
        end
      end
    end

    The only thing i dont understand is, what is the deal with private being in the middle?

    Thank you!
    Last edited by Pullo; Jul 28, 2013 at 05:46. Reason: Added code tags
    "Oh, and Jenkins--apparently your mother died this morning."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •