Class: Stylish::Declarations

Inherits:
Array
  • Object
show all
Includes:
Formattable
Defined in:
lib/stylish/core.rb

Overview

Declarations subclasses Array so that whenever #join is called, the instance’s format attribute will be used as the join string, rather than the empty string.

Instance Method Summary collapse

Methods included from Formattable

included

Instance Method Details

#joinObject

The format attribute is always used as the separator when joining the elements of a Declarations object.



309
310
311
# File 'lib/stylish/core.rb', line 309

def join
  super(self.class.format)
end

#to_s(symbols = {}) ⇒ Object

Returns a string by converting each element to a string, separated by the format attribute. Assuming that its contents are indeed Declaration objects, this will invoke their own #to_s method and generating correct CSS code.



317
318
319
320
321
# File 'lib/stylish/core.rb', line 317

def to_s(symbols = {})
  self.inject("") do |a, o|
    a << (a.empty? ? "" : self.class.format) << o.to_s(symbols)
  end
end