Class: WWW_App::Code_ify

Inherits:
BasicObject
Defined in:
lib/www_app/source.rb

Instance Method Summary collapse

Constructor Details

#initialize(&blok) ⇒ Code_ify

Returns a new instance of Code_ify.



5
6
7
8
9
10
# File 'lib/www_app/source.rb', line 5

def initialize &blok
  @code = []
  @target = @code
  @indent = []
  instance_eval(&blok) if blok
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &blok) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/www_app/source.rb', line 12

def method_missing *args, &blok
  @target << {:name=>args.shift, :args=>args}

  if blok
    @indent << 1
    @target.last[:blok] = []
    @target.last[:indent] = @indent.size

    orig = @target
    @target = @target.last[:blok]
    instance_eval(&blok)

    @indent.pop
    @target = orig
  end

  self
end

Instance Method Details

#to_textObject



31
32
33
34
35
# File 'lib/www_app/source.rb', line 31

def to_text
  @code.map { |e|
    to_string e
  }.join "\n".freeze
end