Thursday, 26 February 2015

Healper classes in Ruby using singletons

class Generics  include Singleton
  # creates Singleton Object for Product Update  def self.obj    Generics.instance
  end
  def text_comparison(str1, str2, ignore_case)
    if ignore_case or ignore_case == 'yes'      str1 = str1.strip.downcase
      str2 = str2.strip.downcase
    end    begin      flag = (str1 == str2)
      raise Exception, "String #{str1.inspect} not matching with #{str2.inspect}" if not flag    end  end
end

class UserHelper
  def self.generics
    Generics.obj
  end
end

UserHelper.generics

No comments:

Post a Comment