summaryrefslogtreecommitdiff
path: root/jni/ruby/lib/irb/ext/math-mode.rb
blob: 33e99688e016afd311e97ac26e581d269876a842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
#   math-mode.rb -
#       $Release Version: 0.9.6$
#       $Revision: 47112 $
#       by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
#
#
require "mathn"

module IRB
  class Context
    # Returns whether bc mode is enabled.
    #
    # See #math_mode=
    attr_reader :math_mode
    # Alias for #math_mode
    alias math? math_mode

    # Sets bc mode, which loads +lib/mathn.rb+ so fractions or matrix are
    # available.
    #
    # Also available as the +-m+ command line option.
    #
    # See IRB@Command+line+options and the unix manpage <code>bc(1)</code> for
    # more information.
    def math_mode=(opt)
      if @math_mode == true && !opt
        IRB.fail CantReturnToNormalMode
        return
      end

      @math_mode = opt
      if math_mode
        main.extend Math
        print "start math mode\n" if verbose?
      end
    end

    def inspect?
      @inspect_mode.nil? && !@math_mode or @inspect_mode
    end
  end
end