The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Digging Deep with Instance_eval

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Digging Deep with Instance_eval Posted: Jun 1, 2005 4:27 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Digging Deep with Instance_eval
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

I feel like instance_eval deserves a friendlier name. Especially when used in tandem with a block to reach down inside an object for a moment.

A great example of this is on the RubyGarden wiki under RubyStyleGuide/InjectComplexTestsIntoObjects. The challenge is to reduce the redundancy of the below.

 f = open("myfile")
 if f.stat.readable? and f.stat.writable? and f.stat.size? and f.stat.owned?
   # work with file
 end

My favorite solution involves instance_eval, but see how long and ugly it looks? Perhaps an answer would be aliasing a name like within for simple block calls to instance_eval.

 f = open("myfile")    
 if f.stat.instance_eval{ readable? and writable? and size? and owned? }
   # work with file
 end

Read: Digging Deep with Instance_eval

Topic: New OpenBSD version Previous Topic   Next Topic Topic: Enterprise Software and Institutionalized Inefficiency

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use