Class: RubyMaxima::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_maxima/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



6
7
8
9
# File 'lib/ruby_maxima/session.rb', line 6

def initialize
  @commands = []
  @debug = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



19
20
21
22
23
# File 'lib/ruby_maxima/session.rb', line 19

def method_missing(method, *args, &block)
  translated_args = args.map {|arg| translate_argument arg }

  @commands << "#{method}(#{translated_args.join ','});"
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



3
4
5
# File 'lib/ruby_maxima/session.rb', line 3

def commands
  @commands
end

#debugObject

Returns the value of attribute debug.



4
5
6
# File 'lib/ruby_maxima/session.rb', line 4

def debug
  @debug
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
# File 'lib/ruby_maxima/session.rb', line 11

def execute
  result = `maxima -r '#{commands.join ' '}'`
  puts result if @debug
  result.scan(
    /(?<=\(%o#{@commands.count}\)).*(?=\(%i\d*\))/m
  ).first.strip
end