Browse Source

Execute class definitions

master
Dylan Baker 5 years ago
parent
commit
37b3c966bf
2 changed files with 14 additions and 0 deletions
  1. 4
    0
      lib/ahem/ast/class_definition.rb
  2. 10
    0
      spec/ast/class_definition_spec.rb

+ 4
- 0
lib/ahem/ast/class_definition.rb View File

@@ -12,4 +12,8 @@ class AST::ClassDefinition
12 12
       other.members == @members &&
13 13
       other.methods == @methods
14 14
   end
15
+
16
+  def execute(env)
17
+    env.set(@name.name, self)
18
+  end
15 19
 end

+ 10
- 0
spec/ast/class_definition_spec.rb View File

@@ -0,0 +1,10 @@
1
+RSpec.describe AST::ClassDefinition do
2
+  it 'defines a class' do
3
+    env = Environment.new(env)
4
+    klass = AST::ClassDefinition.new(
5
+      AST::Identifier.new('Class'), [], []
6
+    )
7
+    klass.execute(env)
8
+    expect(env.get('Class')).to eq(klass)
9
+  end
10
+end

Loading…
Cancel
Save