[前][次][番号順一覧][スレッド一覧]

ruby-changes:34004

From: zzak <ko1@a...>
Date: Sun, 25 May 2014 06:54:58 +0900 (JST)
Subject: [ruby-changes:34004] zzak:r46085 (trunk): * vm_eval.c: [DOC] [ci skip] Improve instance_eval description when given a

zzak	2014-05-25 06:52:31 +0900 (Sun, 25 May 2014)

  New Revision: 46085

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46085

  Log:
    * vm_eval.c: [DOC] [ci skip] Improve instance_eval description when given a
      block or String arguments. By @nathanl via documenting-ruby/ruby#28

  Modified files:
    trunk/ChangeLog
    trunk/vm_eval.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46084)
+++ ChangeLog	(revision 46085)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 25 06:50:19 2014  Zachary Scott  <e@z...>
+
+	* vm_eval.c: [DOC] Improve instance_eval description when given a
+	  block or String arguments. By @nathanl via documenting-ruby/ruby#28
+
 Sun May 25 06:29:39 2014  Zachary Scott  <e@z...>
 
 	* array.c: [DOC] Clarify default argument for Array.new.
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 46084)
+++ vm_eval.c	(revision 46085)
@@ -1595,24 +1595,34 @@ specific_eval(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1595
 /*
  *  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 <code>instance_eval</code>
- *  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 <code>instance_eval</code> is given a block, _obj_ is also
+ *  passed in as the block's only argument.
+ *
+ *  When <code>instance_eval</code> 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]