Module: Wolfram::Util

Included in:
Assumption, Pod, Result
Defined in:
lib/wolfram/util.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.module_get(mod, name) ⇒ Object

Finds or creates a module by name for a given module



18
19
20
21
# File 'lib/wolfram/util.rb', line 18

def self.module_get(mod, name)
  mod.const_defined?(name, false) ? mod.const_get(name) :
    mod.const_set(name, Module.new)
end

.to_param(obj) ⇒ Object

From activesupport



13
14
15
# File 'lib/wolfram/util.rb', line 13

def self.to_param(obj)
  obj.map {|key, value| to_query(value, key) }.sort * '&'
end

.to_query(obj, key) ⇒ Object

From activesupport



7
8
9
10
# File 'lib/wolfram/util.rb', line 7

def self.to_query(obj, key)
  obj.is_a?(Array) ? obj.map {|e| to_query(e, key) } * '&' :
  "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(obj.to_s)}"
end

Instance Method Details

#delegate(*meths) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
# File 'lib/wolfram/util.rb', line 23

def delegate(*meths)
  raise ArgumentError unless meths[-1].is_a?(Hash) && meths[-1].key?(:to)
  to_meth = meths.pop[:to]
  meths.each do |meth|
    define_method(meth) do |*args, &block|
      self.send(to_meth).send(meth, *args, &block)
    end
  end
end