Sha256: c63df8e6430fe6bd4fd212b7027de88125af3f4974537f3285df7b5eedf30836

Contents?: true

Size: 1.18 KB

Versions: 22

Compression:

Stored size: 1.18 KB

Contents

require 'yaml'
# support methods to remove dependencies on ActiveSupport
class String
  def present?
    !blank?
  end

  def blank?
    if respond_to?(:empty?) && respond_to?(:strip) 
      empty? or strip.empty? 
    elsif respond_to?(:empty?) 
      empty? 
    else 
      !self 
    end     
  end
end

class Hash
  alias_method :blank?, :empty? 

  def present?
    !blank?
  end   
end

class Object
  def present?
    self.class!=NilClass
  end
end

class NilClass #:nodoc: 
  def blank? 
    true 
  end 

  def present?
    false
  end
end

module Accessorize
  module ClassMethods
    def cattr_accessor(*syms)
      syms.flatten.each do |sym|
        class_eval(<<-EOS, __FILE__, __LINE__)
          unless defined? @@#{sym}
            @@#{sym} = nil
          end

          def self.#{sym}
            @@#{sym}
          end

          def #{sym}=(value)
            @@#{sym} = value
          end

          def self.#{sym}=(value)
            @@#{sym} = value
          end

          def #{sym}
            @@#{sym}
          end
        EOS
      end
    end    
  end


  def self.included(receiver)
    receiver.extend         ClassMethods
  end
end

Object.send(:include, Accessorize)

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
phone-1.2.3 lib/support.rb
phone-1.2.2 lib/support.rb
phone-1.2.1 lib/support.rb
phonie-2.1.2 lib/phonie/support.rb
phonie-2.1.1 lib/phonie/support.rb
phonie-2.1.0 lib/phonie/support.rb
phonie-2.0.2 lib/phonie/support.rb
phonie-2.0.1 lib/phonie/support.rb
phonie-2.0.0 lib/phonie/support.rb
phonie-1.0.4 lib/phonie/support.rb
phonie-1.0.3 lib/phonie/support.rb
phonie-1.0.2 lib/phonie/support.rb
phonie-1.0.1 lib/phonie/support.rb
superp-phone-1.2.1 lib/support.rb
superp-phone-1.2 lib/support.rb
superp-phone-1.1 lib/support.rb
phone-1.1 lib/support.rb
phone-1.0 lib/support.rb
phone-0.9.9.3 lib/support.rb
elskwid-phone-0.9.9.4 lib/support.rb