From 602f7b5d8267519d910614bb099f96e432b467b7 Mon Sep 17 00:00:00 2001 From: zzak Date: Sat, 24 May 2014 21:52:31 +0000 Subject: * vm_eval.c: [DOC] [ci skip] Improve instance_eval description when given a block or String arguments. By @nathanl via documenting-ruby/ruby#28 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_eval.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'vm_eval.c') diff --git a/vm_eval.c b/vm_eval.c index 96bbab3ba5..d0b2b1e37d 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1595,24 +1595,34 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) /* * call-seq: * obj.instance_eval(string [, filename [, lineno]] ) -> obj - * obj.instance_eval {| | block } -> obj + * obj.instance_eval {|obj| block } -> obj * * Evaluates a string containing Ruby source code, or the given block, * within the context of the receiver (_obj_). In order to set the * context, the variable +self+ is set to _obj_ while * the code is executing, giving the code access to _obj_'s - * instance variables. In the version of instance_eval - * that takes a +String+, the optional second and third - * parameters supply a filename and starting line number that are used - * when reporting compilation errors. + * instance variables and private methods. + * + * When instance_eval is given a block, _obj_ is also + * passed in as the block's only argument. + * + * When instance_eval is given a +String+, the optional + * second and third parameters supply a filename and starting line number + * that are used when reporting compilation errors. * * class KlassWithSecret * def initialize * @secret = 99 * end + * private + * def the_secret + * "Ssssh! The secret is #{@secret}." + * end * end * k = KlassWithSecret.new - * k.instance_eval { @secret } #=> 99 + * k.instance_eval { @secret } #=> 99 + * k.instance_eval { the_secret } #=> "Ssssh! The secret is 99." + * k.instance_eval {|obj| obj == self } #=> true */ VALUE -- cgit v1.2.3