Sha256: e2d83e6538d4c9a28b3bf15aaa19d627cddb7bd46d53458ea2e978f0b50ba95a

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

#
#       ActiveFacts Runtime API.
#       Various additions or patches to Ruby built-in classes, and some global support methods
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#

# Define Infinity as a constant, if it's not already defined:
# We use this to define open-ended ranges.
unless Object.const_defined?("Infinity")
  Infinity = 1.0/0.0
end

class Symbol #:nodoc:
  def to_proc
    Proc.new{|*args| args.shift.__send__(self, *args)}
  end
end

class String #:nodoc:
  # This may be overridden by a version from ActiveSupport. For our purposes, either will work.
  def camelcase(first_letter = :upper)
    if first_letter == :upper
      gsub(/(^|[_\s]+)([A-Za-z])/){ $2.upcase }
    else
      gsub(/([_\s]+)([A-Za-z])/){ $2.upcase }
    end
  end

  def snakecase
    gsub(/([^_])([A-Z][a-z])/,'\1_\2').downcase
  end

  def camelwords
    gsub(/-([a-zA-Z])/){ $1.upcase }.                 # Break and upcase on hyphenated words
      gsub(/([a-z])([A-Z])/,'\1_\2').
      split(/[_\s]+/)
  end
end

class Module #:nodoc:
  def modspace
    space = name[ 0...(name.rindex( '::' ) || 0)]
    space == '' ? Object : eval(space)
  end

  def basename
    name.gsub(/.*::/, '')
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
activefacts-api-1.9.10 lib/activefacts/api/support.rb
activefacts-api-1.9.9 lib/activefacts/api/support.rb
activefacts-api-1.9.8 lib/activefacts/api/support.rb
activefacts-api-1.9.6 lib/activefacts/api/support.rb
activefacts-api-1.9.5 lib/activefacts/api/support.rb
activefacts-api-1.9.4 lib/activefacts/api/support.rb
activefacts-api-1.9.2 lib/activefacts/api/support.rb
activefacts-api-1.9.0 lib/activefacts/api/support.rb
activefacts-api-1.8.5 lib/activefacts/api/support.rb
activefacts-api-1.8.4 lib/activefacts/api/support.rb
activefacts-api-1.8.3 lib/activefacts/api/support.rb
activefacts-api-1.8.1 lib/activefacts/api/support.rb
activefacts-api-1.8.0 lib/activefacts/api/support.rb
activefacts-api-1.7.1 lib/activefacts/api/support.rb
activefacts-api-1.7.0 lib/activefacts/api/support.rb
activefacts-api-1.6.0 lib/activefacts/api/support.rb
activefacts-api-1.5.0 lib/activefacts/api/support.rb
activefacts-api-1.4.0 lib/activefacts/api/support.rb