Skip to content

Instantly share code, notes, and snippets.

@citizen428
Created March 21, 2012 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citizen428/2146609 to your computer and use it in GitHub Desktop.
Save citizen428/2146609 to your computer and use it in GitHub Desktop.
ActionScript-like "with" for Ruby, result of SO discussion
module Kernel
def with(obj, &block)
obj.instance_eval &block
obj
end
end
module Kernel
def with(obj, &block)
obj.instance_eval &block
obj
end
end
class Person
attr_accessor :name, :example
end
tester = with(Person.new) do
self.name = "Andy"
self.example = "Example"
end
puts "#{tester.name}:#{tester.example}"
@padde
Copy link

padde commented Mar 21, 2012

That makes sense. Thank you very much for explaining this in detail!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment