Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shortcut the get-the-metaclass syntax

  • Loading branch information...
commit 43e0e042cd40b74527dfeae19c75dd394c0167ae 1 parent 1decd96
Evan Phoenix authored
Showing with 27 additions and 0 deletions.
  1. +7 −0 lib/compiler/ast/definitions.rb
  2. +20 −0 spec/compiler/sclass_spec.rb
View
7 lib/compiler/ast/definitions.rb
@@ -601,6 +601,13 @@ def bytecode(g)
g.send :object_metaclass, 1
if @body
+ # if @body just returns self, don't bother with it.
+ if @body.kind_of? Block
+ ary = @body.array
+ return if ary.size == 1 and ary[0].kind_of? Self
+ end
+
+ # Ok, emit it.
attach_and_call g, :__metaclass_init__, true
else
g.pop
View
20 spec/compiler/sclass_spec.rb
@@ -132,4 +132,24 @@ class << x
end
end
end
+
+ relates <<-ruby do
+ x = "a"
+ class << x
+ self
+ end
+ ruby
+
+ compile do |g|
+ g.push_literal "a"
+ g.string_dup
+ g.set_local 0
+ g.pop
+
+ g.push_local 0
+ g.push_const :Rubinius
+ g.swap
+ g.send :object_metaclass, 1
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.