lib/delorean/base.rb in delorean_lang-0.1.6 vs lib/delorean/base.rb in delorean_lang-0.1.7

- old
+ new

@@ -16,35 +16,59 @@ reverse: [Array], slice: [Array, Fixnum, Fixnum], sort: [Array], split: [String, String], uniq: [Array], + sum: [Array], + zip: [Array, [Array, Array, Array]], + index: [Array, [Integer, Numeric, String, Array, Fixnum]], + product: [Array, Array], + first: [Enumerable, [nil, Fixnum]], + keys: [Hash], + values: [Hash], + upcase: [String], + downcase: [String], + match: [String, [String], [nil, Fixnum]], + hour: [[Date, Time, ActiveSupport::TimeWithZone]], min: [[Date, Time, ActiveSupport::TimeWithZone, Array]], sec: [[Date, Time, ActiveSupport::TimeWithZone]], to_date: [[Date, Time, ActiveSupport::TimeWithZone]], month: [[Date, Time, ActiveSupport::TimeWithZone]], day: [[Date, Time, ActiveSupport::TimeWithZone]], year: [[Date, Time, ActiveSupport::TimeWithZone]], + next_month: [[Date, Time, ActiveSupport::TimeWithZone], + [nil, Fixnum], + ], + prev_month: [[Date, Time, ActiveSupport::TimeWithZone], + [nil, Fixnum], + ], + + beginning_of_month: [[Date, Time, ActiveSupport::TimeWithZone]], + + end_of_month: [[Date, Time, ActiveSupport::TimeWithZone]], + + next_day: [[Date, Time, ActiveSupport::TimeWithZone], + [nil, Fixnum], + ], + prev_day: [[Date, Time, ActiveSupport::TimeWithZone], + [nil, Fixnum], + ], + to_i: [[Numeric, String]], to_f: [[Numeric, String]], to_d: [[Numeric, String]], to_s: [Object], abs: [Numeric], round: [Numeric, [nil, Integer]], } module BaseModule - class NodeCall - attr_reader :engine, :node, :params - def initialize(engine, node, params) - @engine, @node, @params = engine, node, params - end - + class NodeCall < Struct.new(:_e, :engine, :node, :params) def evaluate(attr) engine.evaluate(node, attr, params) end def %(args) @@ -55,11 +79,10 @@ } end end class BaseClass - def self._get_attr(obj, attr, _e) return nil if obj.nil? # NOTE: should keep this function consistent with _index @@ -112,14 +135,18 @@ def self._err(*args) str = args.map(&:to_s).join(", ") raise str end - def self._node_call(node, mname, _e, params) + def self._node_call(node, _e, params) context = _e[:_engine] - engine = mname ? context.get_import_engine(mname) : context - NodeCall.new(engine, node || self, params) + + engine = node.is_a?(Class) && + context.module_name != node.module_name ? + context.get_import_engine(node.module_name) : context + + NodeCall.new(_e, engine, node || self, params) end ###################################################################### def self._instance_call(obj, method, args) @@ -148,10 +175,10 @@ if (sc.nil? && i>=arglist.length) || (sc && ai.class <= sc) ok = true break end } - raise "bad arg #{i} to method #{method}: #{ai}/#{ai.class} #{s}" unless ok + raise "bad arg #{i}, method #{method}: #{ai}/#{ai.class} #{s}" if !ok } obj.send(msg, *args) end