Created
August 26, 2008 22:00
-
-
Save therealadam/7367 to your computer and use it in GitHub Desktop.
'with' keyword for Ruby, if that's your thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
def with(obj, &block) | |
obj.instance_eval(&block) | |
end | |
end | |
with 'Hi' do | |
length # => 2 | |
upcase # => "HI" | |
downcase # => "hi" | |
foo = length | |
foo + 2 # => 4 | |
Math.sin(1) # => 0.841470984807897 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment