Skip to content

Instantly share code, notes, and snippets.

@brixen
Created October 12, 2012 21:36
Show Gist options
  • Save brixen/3881661 to your computer and use it in GitHub Desktop.
Save brixen/3881661 to your computer and use it in GitHub Desktop.
sasha:rubinius brian$ rbx compile -A -e "
class Foo
include Module.new {
def this_works
end
}
include Module.new do
def this_doesnt_work
end
end
end
foo = Foo.new
foo.this_works
foo.this_doesnt_work
"
Script
@file: "(snippet)"
@pre_exe: []
@name: :__script__
@body: \
Block
@array: [
Class [0]
@line: 2
@name: \
ClassName
@name: :Foo
@line: 2
@superclass: \
NilLiteral
@line: 2
@superclass: \
NilLiteral
@line: 2
@body: \
ClassScope
@name: :Foo
@line: 2
@body: \
Block
@array: [
SendWithArguments [0]
@privately: true
@name: :include
@check_for_local: false
@block: nil
@line: 6
@vcall_style: false
@receiver: \
Self
@line: 6
@arguments: \
ActualArguments
@array: [
SendFastNew [0]
@privately: false
@name: :new
@check_for_local: false
@line: 3
@vcall_style: false
@receiver: \
ConstantAccess
@name: :Module
@line: 3
@block: \
Iter19
@line: 3
@locals: nil
@arguments: \
FormalArguments19
@names: []
@optional: []
@post: []
@line: 3
@defaults: nil
@required: []
@splat: nil
@block_arg: nil
@splat_index: nil
@body: \
Define
@name: :this_works
@line: 4
@arguments: \
FormalArguments19
@names: []
@optional: []
@post: []
@line: 4
@defaults: nil
@required: []
@splat: nil
@block_arg: nil
@splat_index: nil
@body: \
Block
@array: [
NilLiteral [0]
@line: 5
]
@locals: nil
@line: 5
@arguments: \
ActualArguments
@array: []
@splat: nil
@line: 3
]
@splat: nil
@line: 6
SendWithArguments [1]
@privately: true
@name: :include
@check_for_local: false
@line: 8
@vcall_style: false
@receiver: \
Self
@line: 8
@block: \
Iter19
@line: 8
@locals: nil
@arguments: \
FormalArguments19
@names: []
@optional: []
@post: []
@line: 8
@defaults: nil
@required: []
@splat: nil
@block_arg: nil
@splat_index: nil
@body: \
Define
@name: :this_doesnt_work
@line: 9
@arguments: \
FormalArguments19
@names: []
@optional: []
@post: []
@line: 9
@defaults: nil
@required: []
@splat: nil
@block_arg: nil
@splat_index: nil
@body: \
Block
@array: [
NilLiteral [0]
@line: 10
]
@locals: nil
@line: 10
@arguments: \
ActualArguments
@array: [
SendFastNew [0]
@privately: false
@name: :new
@check_for_local: false
@block: nil
@line: 8
@vcall_style: false
@receiver: \
ConstantAccess
@name: :Module
@line: 8
@arguments: \
ActualArguments
@array: []
@splat: nil
@line: 8
]
@splat: nil
@line: 8
]
@locals: nil
@line: 6
LocalVariableAssignment [1]
@name: :foo
@line: 14
@variable: nil
@value: \
SendFastNew
@privately: false
@name: :new
@check_for_local: false
@block: nil
@line: 14
@vcall_style: false
@receiver: \
ConstantAccess
@name: :Foo
@line: 14
@arguments: \
ActualArguments
@array: []
@splat: nil
@line: 14
Send [2]
@privately: false
@name: :this_works
@check_for_local: false
@block: nil
@line: 15
@vcall_style: false
@receiver: \
LocalVariableAccess
@name: :foo
@line: 15
@variable: nil
Send [3]
@privately: false
@name: :this_doesnt_work
@check_for_local: false
@block: nil
@line: 16
@vcall_style: false
@receiver: \
LocalVariableAccess
@name: :foo
@line: 16
@variable: nil
]
@locals: nil
@line: 2
Ruby syntax can be a bit daunting at times. It can be helpful to look
at the tree structure that represents the syntax. Rubinius has a handy
compile command that produces an S-expression, AST tree, or bytecode
from source code. You can see in the AST here that the @block attribute
of the SendWithArguments node for the #include call contains the block
that you may have thought was going to the Module.new call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment