Class: Console

Inherits:
Object show all
Includes:
Native::Wrapper
Defined in:
opal/stdlib/console.rb

Overview

Manipulate the browser console.

Instance Method Summary collapse

Methods included from Native::Wrapper

included, #initialize, #to_n

Instance Method Details

#clearObject

Clear the console.



12
13
14
# File 'opal/stdlib/console.rb', line 12

def clear
  `#{@native}.clear()`
end

#error(*args) ⇒ Object

Log the passed objects based on an optional initial format as error.



38
39
40
# File 'opal/stdlib/console.rb', line 38

def error(*args)
  `#{@native}.error.apply(#{@native}, args)`
end

#group(*args, &block) ⇒ Object

Group the given block.

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'opal/stdlib/console.rb', line 60

def group(*args, &block)
  raise ArgumentError, 'no block given' unless block

  `#{@native}.group.apply(#{@native}, args)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      yield(self)
    end
  ensure
    `#{@native}.groupEnd()`
  end
end

#group!(*args, &block) ⇒ Object

Group the given block but collapse it.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'opal/stdlib/console.rb', line 77

def group!(*args, &block)
  return unless block_given?

  `#{@native}.groupCollapsed.apply(#{@native}, args)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      yield(self)
    end
  ensure
    `#{@native}.groupEnd()`
  end
end

#info(*args) ⇒ Object

Log the passed objects based on an optional initial format as informational log.



28
29
30
# File 'opal/stdlib/console.rb', line 28

def info(*args)
  `#{@native}.info.apply(#{@native}, args)`
end

#log(*args) ⇒ Object

Log the passed objects based on an optional initial format.



22
23
24
# File 'opal/stdlib/console.rb', line 22

def log(*args)
  `#{@native}.log.apply(#{@native}, args)`
end

#time(label, &block) ⇒ Object

Time the given block with the given label.

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'opal/stdlib/console.rb', line 43

def time(label, &block)
  raise ArgumentError, 'no block given' unless block

  `#{@native}.time(label)`

  begin
    if block.arity == 0
      instance_exec(&block)
    else
      yield(self)
    end
  ensure
    `#{@native}.timeEnd()`
  end
end

#traceObject

Print a stacktrace from the call site.



17
18
19
# File 'opal/stdlib/console.rb', line 17

def trace
  `#{@native}.trace()`
end

#warn(*args) ⇒ Object

Log the passed objects based on an optional initial format as warning.



33
34
35
# File 'opal/stdlib/console.rb', line 33

def warn(*args)
  `#{@native}.warn.apply(#{@native}, args)`
end