Project

with

0.0
No commit activity in last 3 years
No release in over 3 years
Stupid Python-like with statement
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

with statement, because Ruby can't miss something that Python has, amirite?

It works almost exactly as the Python with statement, except you can pass more than one variable to it.

If there's an __enter__ method it calls it, and if there's an __exit__ method it calls it passing the eventual Exception. If any __exit__ returns true when an exception has been raised it is ignored, if nothing returns true the exception is raised again.

If you want Python-like functionality for standard objects (for example passing an IO object to the with and having it closed) you can require 'with/adapters', otherwise those features are not present.

Example:

require 'with'
require 'with/adapters'

with File.new(ARGV.first, ?r) do |f|
  f.read
end # this will return the contents of the passed path