diff options
| -rw-r--r-- | doc/string/scrub.rdoc | 2 | ||||
| -rw-r--r-- | internal/string.h | 2 | ||||
| -rw-r--r-- | vm_eval.c | 43 |
3 files changed, 32 insertions, 15 deletions
diff --git a/doc/string/scrub.rdoc b/doc/string/scrub.rdoc index 5ace376cdb..314b28c465 100644 --- a/doc/string/scrub.rdoc +++ b/doc/string/scrub.rdoc @@ -5,7 +5,7 @@ With no block given, replaces each invalid sequence with the given +default_replacement_string+ (by default, <tt>"�"</tt> for a Unicode encoding, <tt>'?'</tt> otherwise): - "foo\x81\x81bar"scrub # => "foo��bar" + "foo\x81\x81bar".scrub # => "foo��bar" "foo\x81\x81bar".force_encoding('US-ASCII').scrub # => "foo??bar" "foo\x81\x81bar".scrub('xyzzy') # => "fooxyzzyxyzzybar" diff --git a/internal/string.h b/internal/string.h index 9212ce8986..02e708d341 100644 --- a/internal/string.h +++ b/internal/string.h @@ -38,7 +38,7 @@ rb_str_encindex_fastpath(int encindex) // Hence you can use fast, single byte algorithms on them, such as `memchr` etc, // without all the overhead of fetching the rb_encoding and using functions such as // rb_enc_mbminlen etc. - // Many other encodings could qualify, but they are expected to be rare occurences, + // Many other encodings could qualify, but they are expected to be rare occurrences, // so it's better to keep that list small. switch (encindex) { case ENCINDEX_ASCII_8BIT: @@ -2031,21 +2031,38 @@ eval_string_with_scope(VALUE scope, VALUE src, VALUE file, int line) } /* - * call-seq: - * eval(string [, binding [, filename [,lineno]]]) -> obj + * call-seq: + * eval(string, binding = nil, filename = default_filename, lineno = 1) -> obj * - * Evaluates the Ruby expression(s) in <em>string</em>. If - * <em>binding</em> is given, which must be a Binding object, the - * evaluation is performed in its context. If the optional - * <em>filename</em> and <em>lineno</em> parameters are present, they - * will be used when reporting syntax errors. + * Evaluates the Ruby expression(s) in +string+. Returns the result of the last + * expression. * - * def get_binding(str) - * return binding - * end - * str = "hello" - * eval "str + ' Fred'" #=> "hello Fred" - * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred" + * str = "Hello" + * eval("str + ' World'") # => "Hello World" + * + * If +binding+ is given, which must be a Binding object, the + * evaluation is performed in its context. Otherwise, the + * evaluation is performed in the context of the caller. + * + * def get_binding(str) = binding + * str = "Hello" + * eval("str + ' World'", get_binding("Bye")) # => "Bye World" + * + * If the optional +filename+ is given, it will be used as the + * filename of the evaluation (for <tt>__FILE__</tt> and errors). + * Otherwise, it will default to <tt>(eval at __FILE__:__LINE__)</tt> + * where <tt>__FILE__</tt> and <tt>__LINE__</tt> are the filename and + * line number of the caller, respectively. + * + * eval("puts __FILE__") # => "(eval at test.rb:1)" + * eval("puts __FILE__", nil, "foobar.rb") # => "foobar.rb" + * + * If the optional +lineno+ is given, it will be used as the + * line number of the evaluation (for <tt>__LINE__</tt> and errors). + * Otherwise, it will default to 1. + * + * eval("puts __LINE__") # => 1 + * eval("puts __LINE__", nil, "foobar.rb", 10) # => 10 */ VALUE |
