Module: Cowtech::Extensions

Defined in:
lib/cowtech-extensions.rb,
lib/cowtech-extensions/hash.rb,
lib/cowtech-extensions/math.rb,
lib/cowtech-extensions/object.rb,
lib/cowtech-extensions/string.rb,
lib/cowtech-extensions/boolean.rb,
lib/cowtech-extensions/version.rb,
lib/cowtech-extensions/datetime.rb,
lib/cowtech-extensions/pathname.rb,
lib/cowtech-extensions/settings.rb,
lib/cowtech-extensions/exceptions.rb

Overview

Several Ruby object enhancements.

Defined Under Namespace

Modules: Boolean, DateTime, Exceptions, Hash, Math, Object, Pathname, String, TimeZone, Version Classes: Settings

Class Method Summary collapse

Class Method Details

.is_ruby_18?Boolean

Checks if we are running under Ruby 1.8

Returns:

  • (Boolean)

    true for Ruby 1.8, false otherwise.



31
32
33
# File 'lib/cowtech-extensions.rb', line 31

def self.is_ruby_18?
  RUBY_VERSION =~ /^1\.8/
end

.load!(*what) ⇒ Settings

Loads the extensions.

Parameters:

  • what (Array)

    The modules to load. Valid values are: @option object Extensions for all objects. @option boolean Extensions for boolean values. @option string Extensions for strings. @option hash Extensions for hashs. @option datetime Extensions date and time objects. @option math Extensions for Math module. @option pathname Extensions for path objects.

Returns:

  • (Settings)

    The settings for the extensions.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/cowtech-extensions.rb', line 53

def self.load!(*what)
	what = ["object", "boolean", "string", "hash", "datetime", "math", "pathname"] if what.count == 0
	what.collect! { |w| w.to_s }

    # Dependency resolving
    what << "object" if what.include?("datetime")
    what << "object" if what.include?("math")
    what.compact.uniq!

	if what.include?("object") then
		::Object.class_eval do
			include ::Cowtech::Extensions::Object
		end
	end

	if what.include?("boolean") then
		::TrueClass.class_eval do
			include ::Cowtech::Extensions::Object
			include ::Cowtech::Extensions::Boolean
      end

		::FalseClass.class_eval do
        include ::Cowtech::Extensions::Object
        include ::Cowtech::Extensions::Boolean
		end
    end

	if what.include?("string") then
		::String.class_eval do
			include ::Cowtech::Extensions::String
		end
	end

	if what.include?("hash") then
		::Hash.class_eval do
			include ::Cowtech::Extensions::Hash
		end
	end

	if what.include?("datetime") then
		::Time.class_eval do
			include ::Cowtech::Extensions::DateTime
		end

		::Date.class_eval do
			include ::Cowtech::Extensions::DateTime
		end

		::DateTime.class_eval do
			include ::Cowtech::Extensions::DateTime
      end

      ::ActiveSupport::TimeZone.class_eval do
        include ::Cowtech::Extensions::TimeZone
      end
	end

	if what.include?("math") then
		::Math.class_eval do
			include ::Cowtech::Extensions::Math
		end
	end

	if what.include?("pathname") then
		require "pathname"

		::Pathname.class_eval do
			include ::Cowtech::Extensions::Pathname
		end
    end

    yield if block_given?

    ::Cowtech::Extensions::Settings.instance
end

.settingsSettings

Returns the settings for the extensions

Returns:

  • (Settings)

    The settings for the extensions.



38
39
40
# File 'lib/cowtech-extensions.rb', line 38

def self.settings
  ::Cowtech::Extensions::Settings.instance
end