Skip to content

Commit 49cf042

Browse files
committed
[PRISM] Define DATA constant when parsing stdin and __END__
1 parent 1e4c4fe commit 49cf042

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ruby.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,13 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
21342134

21352135
ruby_opt_init(opt);
21362136
error = pm_parse_stdin(result);
2137+
2138+
// If we found an __END__ marker, then we're going to define a global
2139+
// DATA constant that is a file object that can be read to read the
2140+
// contents after the marker.
2141+
if (NIL_P(error) && result->parser.data_loc.start != NULL) {
2142+
rb_define_global_const("DATA", rb_stdin);
2143+
}
21372144
}
21382145
else if (opt->e_script) {
21392146
command_line |= PM_OPTIONS_COMMAND_LINE_E;

0 commit comments

Comments
 (0)