util.rb

Path: lib/sass/util.rb
Last Update: Thu Sep 20 07:26:10 +0200 2012

Required files

erb   set   enumerator   stringio   strscan   rbconfig   sass/root   sass/util/subset_map   sass/script/string   sass/script/number   sass/script/color   sass/script/bool   sass/script/list  

Methods

Public Instance methods

A version of `Enumerable#enum_cons` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @param n [Fixnum] The size of each cons @return [Enumerator] The consed enumerator

A version of `Enumerable#enum_slice` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @param n [Fixnum] The size of each slice @return [Enumerator] The consed enumerator

A version of `Enumerable#enum_with_index` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @return [Enumerator] The with-index enumerator

Flattens the first `n` nested arrays in a cross-version manner.

@param arr [Array] The array to flatten @param n [Fixnum] The number of levels to flatten @return [Array] The flattened array

Checks to see if a class has a given method. For example:

    Sass::Util.has?(:public_instance_method, String, :gsub) #=> true

Method collections like `Class#instance_methods` return strings in Ruby 1.8 and symbols in Ruby 1.9 and on, so this handles checking for them in a compatible way.

@param attr [to_s] The (singular) name of the method-collection method

  (e.g. `:instance_methods`, `:private_methods`)

@param klass [Module] The class to check the methods of which to check @param method [String, Symbol] The name of the method do check for @return [Boolean] Whether or not the given collection has the given method

Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2. This is necessary so that the precompiled Haml template can be `encode`d into `@options[:encoding]` before being evaluated.

@param obj {Object} @return {String}

Returns the ASCII code of the given character.

@param c [String] All characters but the first are ignored. @return [Fixnum] The ASCII code of `c`.

Tests the hash-equality of two sets in a cross-version manner. Aggravatingly, this is order-dependent in Ruby 1.8.6.

@param set1 [Set] @param set2 [Set] @return [Boolean] Whether or not the sets are hashcode equal

Returns the hash code for a set in a cross-version manner. Aggravatingly, this is order-dependent in Ruby 1.8.6.

@param set [Set] @return [Fixnum] The order-independent hashcode of `set`

[Validate]