Class: CSS

Inherits:
Object
  • Object
show all
Defined in:
lib/css.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



23
24
25
26
# File 'lib/css.rb', line 23

def method_missing name, *args, &block
  send(:selector, *args, &block) if block
  send(:property, name, *args, &block) if args[0] and !block
end

Instance Method Details

#property(method, *args, &block) ⇒ Object

Write a css property declaration with the name of the called method

Parameters:

  • method (Symbol)

    the called method name as a symbol



17
18
19
# File 'lib/css.rb', line 17

def property method, *args, &block
  $stdout.write "#{method.to_s.gsub('_', '-')}:#{args[0]};"
end

#selector(selector, &block) ⇒ Object

Write a css selector declaration to $stdout

Parameters:

  • selector (String)

    the selector name or string



11
12
13
# File 'lib/css.rb', line 11

def selector selector, &block
  $stdout.write "#{selector}{"; yield; $stdout.write "}"
end

#style(&block) ⇒ Object

Send a message to the instance_eval method of a CSS instace. It is just an Alias.

Parameters:

  • &block (Proc)

    the code block to be executed in the CSS instance context



5
6
7
# File 'lib/css.rb', line 5

def style &block
  send :instance_eval, &block
end