Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:59:57+00:00 2026-06-06T14:59:57+00:00

Surveying work code (in a module called Surveyor, no less), trying to understand it.

  • 0

Surveying work code (in a module called Surveyor, no less), trying to understand it. I ran across this section that contains a class within a module. Is this the same as including the module? If not, what is the advantage of doing it this way? Thanks. (BONUS POINTS: Why are we appending self to class, is that not already implied?)

module Surveyor
  class Common
    RAND_CHARS = [('a'..'z'), ('A'..'Z'), (0..9)].map{|r| r.to_a}.flatten.join
    OPERATORS = %w(== != < > <= >= =~)

    class << self
      def make_tiny_code(len = 10)
        if RUBY_VERSION < "1.8.7"
          (1..len).to_a.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.join
        else
          len.times.map{|i| RAND_CHARS[rand(RAND_CHARS.size), 1] }.join
        end
      end

      def to_normalized_string(text)
        words_to_omit = %w(a be but has have in is it of on or the to when)
        col_text = text.to_s.gsub(/(<[^>]*>)|\n|\t/su, ' ') # Remove html tags
        col_text.downcase!                            # Remove capitalization
        col_text.gsub!(/\"|\'/u, '')                   # Remove potential problem characters
        col_text.gsub!(/\(.*?\)/u,'')                  # Remove text inside parens
        col_text.gsub!(/\W/u, ' ')                     # Remove all other non-word characters      
        cols = (col_text.split(' ') - words_to_omit)
        (cols.size > 5 ? cols[-5..-1] : cols).join("_")
      end

      def equal_json_excluding_wildcards(a,b)
        return false if a.nil? or b.nil?
        a = a.is_a?(String) ? JSON.load(a) : JSON.load(a.to_json)
        b = b.is_a?(String) ? JSON.load(b) : JSON.load(b.to_json)
        deep_compare_excluding_wildcards(a,b)
      end
      def deep_compare_excluding_wildcards(a,b)
        return false if a.class != b.class
        if a.is_a?(Hash)
          return false if a.size != b.size
          a.each do |k,v|
            return false if deep_compare_excluding_wildcards(v,b[k]) == false
          end
        elsif a.is_a?(Array)
          return false if a.size != b.size
          a.each_with_index{|e,i| return false if deep_compare_excluding_wildcards(e,b[i]) == false }
        else
          return (a == "*") || (b == "*") || (a == b)
        end
        true
      end

      alias :normalize :to_normalized_string

      def generate_api_id
        UUIDTools::UUID.random_create.to_s
      end
    end
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:59:58+00:00Added an answer on June 6, 2026 at 2:59 pm

    what is the advantage of doing it this way?

    It serves as namespace so classes with the same name do not clash (so it has nothing to do with mixins). It’s standard.

    Why are we appending self to class, is that not already implied?

    That’s just one of the ways of defining class-methods (the other being def self.method_name).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is causing a This query contains references to items defined on
What wrong with this code (or my sanity for that matter :D ). The
currently I using this code to count survey responses: $VERYHAPPY = mysql_query(SELECT * FROM
I am not an expert with MySQL, and I am trying to understand why
I have this old survey link that is has been superseded by another link,
I'm currently working on a generational garbage collector. This means that only the most
I have a page that has a form backing object that contains a collections
So I think I already know the answer to this question... Running AdventureWorks2008 (latest
(Followup to this question ) After surviving the first wave of incoming shipments (9
My page has a DetailsView that has a hidden field in it that gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.