Module: Alf::Lang::ObjectOriented::RenderingMethods

Included in:
Alf::Lang::ObjectOriented
Defined in:
lib/alf/lang/oo/rendering_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.def_renderer_method(name, clazz) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/alf/lang/oo/rendering_methods.rb', line 6

def self.def_renderer_method(name, clazz)
  define_method(:"to_#{name}") do |*args|
    options, io = nil
    args.each do |arg|
      options ||= arg if arg.is_a?(Hash)
      io      ||= arg if arg.respond_to?(:<<)
    end
    to_array(options || {}) do |arr|
      io ||= ""
      clazz.new(arr, options).execute(io)
      io
    end
  end
end

Instance Method Details

#to_a(options = nil) ⇒ Object


28
29
30
# File 'lib/alf/lang/oo/rendering_methods.rb', line 28

def to_a(options = nil)
  to_array(options || {})
end

#to_array(options = {}) ⇒ Object


21
22
23
24
25
26
# File 'lib/alf/lang/oo/rendering_methods.rb', line 21

def to_array(options = {})
  _with_ordering(options) do |o|
    op = Alf::Engine::ToArray.new(to_cog, o)
    block_given? ? yield(op) : op.to_a
  end
end