Class: Python::Syntax::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/python/syntax.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Statement

Returns a new instance of Statement.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/python/syntax.rb', line 15

def initialize(*args)
  min_argc = attrs.take_while{|attr| attr.is_a?(Symbol)}.count
  max_argc = attrs.flatten.count
  unless min_argc <= args.length && args.length <= max_argc
    raise "Argument error: failed to make instance of #{self.class.name}." +
          "expected: #{attrs}, actual: #{args}"
  end
  attrs.flatten.zip(args).each do |name, val|
    instance_variable_set("@#{name}".to_sym, val)
  end
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
# File 'lib/python/syntax.rb', line 31

def ==(other)
  self.class == other.class && attrs.flatten.all? do |vname|
    ivname = "@#{vname}".to_sym
    self.instance_variable_get(ivname) == other.instance_variable_get(ivname)
  end
end

#attrsObject



7
8
9
# File 'lib/python/syntax.rb', line 7

def attrs
  []
end

#eval(env) ⇒ Object



27
28
29
# File 'lib/python/syntax.rb', line 27

def eval(env)
  instance_exec(env, &eval_proc)
end

#eval_procObject



11
12
13
# File 'lib/python/syntax.rb', line 11

def eval_proc
  proc{}
end