From: "alexeymuranov (Alexey Muranov)" Date: 2012-07-11T22:14:01+09:00 Subject: [ruby-core:46324] [ruby-trunk - Feature #6717] Method like #instance_eval that returns self (like #tap) Issue #6717 has been updated by alexeymuranov (Alexey Muranov). =begin If nobody has anything interesting to say about this, the issue can be closed, as i think (({tap})) works fine here, even in: hash = {}.tap { |h| h.tap { |hh| hh[1] = 2 } } # => {1=>2} "Tap" just sounded strange to me in this use case. I wanted something like (({instance_eval})) that (1) returns self and (2) can only call public methods. ((*rosenfeld*)), what did you mean by "won't be suitable for nested tweak calls"? =end ---------------------------------------- Feature #6717: Method like #instance_eval that returns self (like #tap) https://bugs.ruby-lang.org/issues/6717#change-27940 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: Category: Target version: =begin How about adding a method that acts like (({#instance_eval})), but returns (({self}))? Call it (({Object#instance_tap})) for example, or (({Object#tweak!})): class Object def tweak!(*args, &block) instance_eval(*args, &block); self end end This can be used to initialize a hash. Instead of: room_numbers = (1..10).each_with_object({}) { |n, o| o[n] = 100 + n } one would write: room_numbers = {}.tweak! { (1..10).each { |n| self[n] = 100 +n } } Googling for this kind of method gave me this: http://yuroyoro-blog.tumblr.com/post/24113917395/ruby-tap-instance-eval-tapeval =end -- http://bugs.ruby-lang.org/