Method: Termular::Context.global

Defined in:
lib/termular/context.rb

.globalObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/termular/context.rb', line 3

def self.global
  @@global ||= begin
    ctx = Context.new
    %w( acos acosh asin asinh atan atan2 atanh cbrt cos cosh erf erfc exp
        log log10 log2 sin sinh sqrt tan tanh ).each do |m|
      ctx[m] = Math.method m
    end
    %w( PI E ).each do |c|
      ctx[c.downcase] = Math.const_get c
    end
    ctx["ln"]     = ctx["log"]
    ctx["abs"]    = ->x { x.abs }
    ctx["arg"]    = ->x { x.arg }
    ctx["ceil"]   = ->x { x.ceil }
    ctx["floor"]  = ->x { x.floor }
    ctx["int"]    = ->x { x.to_i }
    ctx["mod"]    = ->a,b { a % b }
    ctx
  end
end