Created
August 1, 2012 18:51
-
-
Save francescoagati/3229749 to your computer and use it in GitHub Desktop.
who is pippo? ruby runtime variable, methods and closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[:program, | |
[[:class, | |
[:const_ref, [:@const, "Context", [4, 8]]], | |
nil, | |
[:bodystmt, | |
[[:def, | |
[:@ident, "pippo", [6, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:string_literal, | |
[:string_content, [:@tstring_content, "pippo Context", [7, 7]]]]], | |
nil, | |
nil, | |
nil]]], | |
nil, | |
nil, | |
nil]], | |
[:class, | |
[:const_ref, [:@const, "A", [13, 8]]], | |
nil, | |
[:bodystmt, | |
[[:def, | |
[:@ident, "pippo", [16, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:string_literal, | |
[:string_content, [:@tstring_content, "pippo metodo", [17, 7]]]]], | |
nil, | |
nil, | |
nil]], | |
[:def, | |
[:@ident, "pippa", [20, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:assign, | |
[:var_field, [:@ident, "blk", [22, 6]]], | |
[:method_add_block, | |
[:call, | |
[:var_ref, [:@const, "Proc", [22, 10]]], | |
:".", | |
[:@ident, "new", [22, 15]]], | |
[:do_block, | |
nil, | |
[[:command, | |
[:@ident, "p", [23, 8]], | |
[:args_add_block, | |
[[:vcall, [:@ident, "pippo", [23, 10]]]], | |
false]]]]]], | |
[:call, | |
[:var_ref, [:@ident, "blk", [26, 6]]], | |
:".", | |
[:@ident, "call", [26, 10]]], | |
[:method_add_arg, | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "Context", [27, 6]]], | |
:".", | |
[:@ident, "new", [27, 14]]], | |
:".", | |
[:@ident, "instance_eval", [27, 18]]], | |
[:arg_paren, | |
[:args_add_block, [], [:var_ref, [:@ident, "blk", [27, 33]]]]]], | |
[:assign, | |
[:var_field, [:@ident, "pippo", [29, 6]]], | |
[:string_literal, | |
[:string_content, | |
[:@tstring_content, "pippo variabile", [29, 13]]]]], | |
[:assign, | |
[:var_field, [:@ident, "blk", [31, 6]]], | |
[:method_add_block, | |
[:call, | |
[:var_ref, [:@const, "Proc", [31, 10]]], | |
:".", | |
[:@ident, "new", [31, 15]]], | |
[:do_block, | |
nil, | |
[[:command, | |
[:@ident, "p", [32, 8]], | |
[:args_add_block, | |
[[:var_ref, [:@ident, "pippo", [32, 10]]]], | |
false]]]]]], | |
[:call, | |
[:var_ref, [:@ident, "blk", [35, 6]]], | |
:".", | |
[:@ident, "call", [35, 10]]], | |
[:method_add_arg, | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "Context", [36, 6]]], | |
:".", | |
[:@ident, "new", [36, 14]]], | |
:".", | |
[:@ident, "instance_eval", [36, 18]]], | |
[:arg_paren, | |
[:args_add_block, [], [:var_ref, [:@ident, "blk", [36, 33]]]]]]], | |
nil, | |
nil, | |
nil]]], | |
nil, | |
nil, | |
nil]], | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "A", [43, 2]]], | |
:".", | |
[:@ident, "new", [43, 4]]], | |
:".", | |
[:@ident, "pippa", [43, 8]]]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[:program, | |
[[:class, | |
[:const_ref, [:@const, "Context", [4, 8]]], | |
nil, | |
[:bodystmt, | |
[[:def, | |
[:@ident, "pippo", [6, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:string_literal, | |
[:string_content, [:@tstring_content, "pippo Context", [7, 7]]]]], | |
nil, | |
nil, | |
nil]]], | |
nil, | |
nil, | |
nil]], | |
[:class, | |
[:const_ref, [:@const, "A", [13, 8]]], | |
nil, | |
[:bodystmt, | |
[[:def, | |
[:@ident, "pippo", [16, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:string_literal, | |
[:string_content, [:@tstring_content, "pippo metodo", [17, 7]]]]], | |
nil, | |
nil, | |
nil]], | |
[:def, | |
[:@ident, "pippa", [20, 8]], | |
[:params, nil, nil, nil, nil, nil], | |
[:bodystmt, | |
[[:assign, | |
[:var_field, [:@ident, "blk", [22, 6]]], | |
[:method_add_block, | |
[:call, | |
[:var_ref, [:@const, "Proc", [22, 10]]], | |
:".", | |
[:@ident, "new", [22, 15]]], | |
[:do_block, | |
nil, | |
[[:command, | |
[:@ident, "p", [23, 8]], | |
[:args_add_block, | |
[[:vcall, [:@ident, "pippo", [23, 10]]]], | |
false]]]]]], | |
[:call, | |
[:var_ref, [:@ident, "blk", [26, 6]]], | |
:".", | |
[:@ident, "call", [26, 10]]], | |
[:method_add_arg, | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "Context", [27, 6]]], | |
:".", | |
[:@ident, "new", [27, 14]]], | |
:".", | |
[:@ident, "instance_eval", [27, 18]]], | |
[:arg_paren, | |
[:args_add_block, [], [:var_ref, [:@ident, "blk", [27, 33]]]]]], | |
[:assign, | |
[:var_field, [:@ident, "pippo", [29, 6]]], | |
[:string_literal, | |
[:string_content, | |
[:@tstring_content, "pippo variabile", [29, 13]]]]], | |
[:assign, | |
[:var_field, [:@ident, "blk", [31, 6]]], | |
[:method_add_block, | |
[:call, | |
[:var_ref, [:@const, "Proc", [31, 10]]], | |
:".", | |
[:@ident, "new", [31, 15]]], | |
[:do_block, | |
nil, | |
[[:command, | |
[:@ident, "p", [32, 8]], | |
[:args_add_block, | |
[[:var_ref, [:@ident, "pippo", [32, 10]]]], | |
false]]]]]], | |
[:call, | |
[:var_ref, [:@ident, "blk", [35, 6]]], | |
:".", | |
[:@ident, "call", [35, 10]]], | |
[:method_add_arg, | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "Context", [36, 6]]], | |
:".", | |
[:@ident, "new", [36, 14]]], | |
:".", | |
[:@ident, "instance_eval", [36, 18]]], | |
[:arg_paren, | |
[:args_add_block, [], [:var_ref, [:@ident, "blk", [36, 33]]]]]]], | |
nil, | |
nil, | |
nil]]], | |
nil, | |
nil, | |
nil]], | |
[:call, | |
[:call, | |
[:var_ref, [:@const, "A", [43, 2]]], | |
:".", | |
[:@ident, "new", [43, 4]]], | |
:".", | |
[:@ident, "pippa", [43, 8]]]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Context | |
def pippo | |
"pippo Context" | |
end | |
end | |
class A | |
def pippo | |
"pippo metodo" | |
end | |
def pippa | |
blk=Proc.new do | |
p pippo | |
end | |
blk.call | |
Context.new.instance_eval(&blk) | |
pippo="pippo variabile" | |
blk=Proc.new do | |
p pippo | |
end | |
blk.call | |
Context.new.instance_eval(&blk) | |
end | |
end | |
A.new.pippa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment