New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dup_eval

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dup_eval

  • 0.1.4
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Dup_eval

This is an alternative to _why's mix_eval C extension. It provides identical functionality to mix_eval as well as the following extra functionality:

  • Ability to mix in Objects/Classes (using Object2module)
  • Thread-safety

Dup_eval is based on coderrr's idea for dupping the binding of a block (http://coderrr.wordpress.com/2008/11/14/making-mixico-thread-safe/)

NOTE: Dup_eval is still in proof of concept stage, use at own risk!

Example use:

#create our object
o = Object.new

#give it a method
class << o
    def hello; print "Hello! "; end
end

#create a method in the current binding
def goodbye; puts "Goodbye!"; end

o.dup_eval { hello; goodbye }    #=> "Hello! Goodbye!" 

From above, both the methods of the object itself and the binding of the block are available to the block.

#we can also choose which objects we want to eval the block with respect to (we can have more than one)
o1 = Object.new
class << o1; ...define methods here... end

o2 = Object.new
class << o2; ...define methods here... end

o3 = Object.new
class << o3; ...define methods here... end

#create a method in the current binding
def goodbye; puts "Goodbye!"; end

o1.dup_eval_with(o1, o2, o3) { o1_method; o2_method; o3_method; goodbye }

As shown above we can have the block access methods in many objects (as many as we want). The objects may also be either Objects, Classes, or Modules.

FAQs

Package last updated on 25 Jul 2009

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc