class Patm::Pattern::Struct
Public Class Methods
new(klass, pat)
click to toggle source
# File lib/patm.rb, line 354 def initialize(klass, pat) @klass, @pat = klass, pat end
Public Instance Methods
compile_internal(free_index, target_name = "_obj")
click to toggle source
# File lib/patm.rb, line 366 def compile_internal(free_index, target_name = "_obj") srcs = [] ctxs = [] i = free_index if @klass.name srcs << "#{target_name}.is_a?(::#{@klass.name})" else srcs << "#{target_name}.is_a?(_ctx[#{i}])" ctxs << [@klass] i += 1 end @pat.each do|(member, v)| s, c, i = v.compile_internal(i, "#{target_name}_elm") srcs << "#{target_name}_elm = #{target_name}.#{member}; #{s}" if s ctxs << c end [ srcs.map{|s| "(#{s})"}.join(" &&\n"), ctxs.flatten(1), i ] end
execute(match, obj)
click to toggle source
# File lib/patm.rb, line 362 def execute(match, obj) obj.is_a?(@klass) && @pat.all?{|k, v| v.execute(match, obj[k]) } end
inspect()
click to toggle source
# File lib/patm.rb, line 358 def inspect "STRUCT(#{@klass.name || "<unnamed>"}, #{@pat.inspect})" end